diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 5ea5d0cf..9afeabed 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-beta.30" + ".": "0.1.0-beta.31" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 2fab76ed..515f4458 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 111 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stigg/stigg-db0e894e98bd8b3dcb73ff6aaa78775fa84c059a4b1ea8f6ca481ae826affaaa.yml -openapi_spec_hash: 7a1b7f96561158341899feff23422ac6 -config_hash: 2e65c1178cfd5d688faf5c9b1a48a732 +configured_endpoints: 113 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stigg/stigg-5ac3181e71c63e5c6546c3b332853485306095584f73dc3e5942988edec5ab4b.yml +openapi_spec_hash: cb4c8b53e6983a1d06b7b89c742ed74a +config_hash: 7c6fb6cddb559f056a68eaef8c1b9921 diff --git a/CHANGELOG.md b/CHANGELOG.md index bd22fbba..d31c329e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.1.0-beta.31 (2026-07-01) + +Full Changelog: [v0.1.0-beta.30...v0.1.0-beta.31](https://github.com/stiggio/stigg-java/compare/v0.1.0-beta.30...v0.1.0-beta.31) + +### Features + +* **api:** add consume/consumeAsync methods to credits consumption ([32b02b4](https://github.com/stiggio/stigg-java/commit/32b02b4663bf1b98966b08288afc958b03a7d12d)) + ## 0.1.0-beta.30 (2026-06-30) Full Changelog: [v0.1.0-beta.29...v0.1.0-beta.30](https://github.com/stiggio/stigg-java/compare/v0.1.0-beta.29...v0.1.0-beta.30) diff --git a/README.md b/README.md index 272f30f2..27149c7e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/io.stigg/stigg-java)](https://central.sonatype.com/artifact/io.stigg/stigg-java/0.1.0-beta.30) -[![javadoc](https://javadoc.io/badge2/io.stigg/stigg-java/0.1.0-beta.30/javadoc.svg)](https://javadoc.io/doc/io.stigg/stigg-java/0.1.0-beta.30) +[![Maven Central](https://img.shields.io/maven-central/v/io.stigg/stigg-java)](https://central.sonatype.com/artifact/io.stigg/stigg-java/0.1.0-beta.31) +[![javadoc](https://javadoc.io/badge2/io.stigg/stigg-java/0.1.0-beta.31/javadoc.svg)](https://javadoc.io/doc/io.stigg/stigg-java/0.1.0-beta.31) @@ -22,7 +22,7 @@ Use the Stigg MCP Server to enable AI assistants to interact with this API, allo -Javadocs are available on [javadoc.io](https://javadoc.io/doc/io.stigg/stigg-java/0.1.0-beta.30). +Javadocs are available on [javadoc.io](https://javadoc.io/doc/io.stigg/stigg-java/0.1.0-beta.31). @@ -33,7 +33,7 @@ Javadocs are available on [javadoc.io](https://javadoc.io/doc/io.stigg/stigg-jav ### Gradle ```kotlin -implementation("io.stigg:stigg-java:0.1.0-beta.30") +implementation("io.stigg:stigg-java:0.1.0-beta.31") ``` ### Maven @@ -42,7 +42,7 @@ implementation("io.stigg:stigg-java:0.1.0-beta.30") io.stigg stigg-java - 0.1.0-beta.30 + 0.1.0-beta.31 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 7a9f96a0..6fd168d3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "io.stigg" - version = "0.1.0-beta.30" // x-release-please-version + version = "0.1.0-beta.31" // x-release-please-version } subprojects { diff --git a/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncParams.kt b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncParams.kt new file mode 100644 index 00000000..73b4c9b0 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncParams.kt @@ -0,0 +1,1056 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +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 io.stigg.core.ExcludeMissing +import io.stigg.core.JsonField +import io.stigg.core.JsonMissing +import io.stigg.core.JsonValue +import io.stigg.core.Params +import io.stigg.core.checkKnown +import io.stigg.core.checkRequired +import io.stigg.core.http.Headers +import io.stigg.core.http.QueryParams +import io.stigg.core.toImmutable +import io.stigg.errors.StiggInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Consumes credits directly from customer wallets asynchronously. Consumptions are reconciled + * asynchronously into the credit balances. + */ +class ConsumptionConsumeAsyncParams +private constructor( + private val xAccountId: String?, + private val xEnvironmentId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun xAccountId(): Optional = Optional.ofNullable(xAccountId) + + fun xEnvironmentId(): Optional = Optional.ofNullable(xEnvironmentId) + + /** + * The credit consumptions to report (up to 1000) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun consumptions(): List = body.consumptions() + + /** + * Returns the raw JSON value of [consumptions]. + * + * Unlike [consumptions], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _consumptions(): JsonField> = body._consumptions() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ConsumptionConsumeAsyncParams]. + * + * The following fields are required: + * ```java + * .consumptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ConsumptionConsumeAsyncParams]. */ + class Builder internal constructor() { + + private var xAccountId: String? = null + private var xEnvironmentId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(consumptionConsumeAsyncParams: ConsumptionConsumeAsyncParams) = apply { + xAccountId = consumptionConsumeAsyncParams.xAccountId + xEnvironmentId = consumptionConsumeAsyncParams.xEnvironmentId + body = consumptionConsumeAsyncParams.body.toBuilder() + additionalHeaders = consumptionConsumeAsyncParams.additionalHeaders.toBuilder() + additionalQueryParams = consumptionConsumeAsyncParams.additionalQueryParams.toBuilder() + } + + fun xAccountId(xAccountId: String?) = apply { this.xAccountId = xAccountId } + + /** Alias for calling [Builder.xAccountId] with `xAccountId.orElse(null)`. */ + fun xAccountId(xAccountId: Optional) = xAccountId(xAccountId.getOrNull()) + + fun xEnvironmentId(xEnvironmentId: String?) = apply { this.xEnvironmentId = xEnvironmentId } + + /** Alias for calling [Builder.xEnvironmentId] with `xEnvironmentId.orElse(null)`. */ + fun xEnvironmentId(xEnvironmentId: Optional) = + xEnvironmentId(xEnvironmentId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [consumptions] + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The credit consumptions to report (up to 1000) */ + fun consumptions(consumptions: List) = apply { + body.consumptions(consumptions) + } + + /** + * Sets [Builder.consumptions] to an arbitrary JSON value. + * + * You should usually call [Builder.consumptions] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun consumptions(consumptions: JsonField>) = apply { + body.consumptions(consumptions) + } + + /** + * Adds a single [Consumption] to [consumptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addConsumption(consumption: Consumption) = apply { body.addConsumption(consumption) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ConsumptionConsumeAsyncParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .consumptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionConsumeAsyncParams = + ConsumptionConsumeAsyncParams( + xAccountId, + xEnvironmentId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = + Headers.builder() + .apply { + xAccountId?.let { put("X-ACCOUNT-ID", it) } + xEnvironmentId?.let { put("X-ENVIRONMENT-ID", it) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Request body for consuming credits directly from wallets asynchronously */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val consumptions: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("consumptions") + @ExcludeMissing + consumptions: JsonField> = JsonMissing.of() + ) : this(consumptions, mutableMapOf()) + + /** + * The credit consumptions to report (up to 1000) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun consumptions(): List = consumptions.getRequired("consumptions") + + /** + * Returns the raw JSON value of [consumptions]. + * + * Unlike [consumptions], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("consumptions") + @ExcludeMissing + fun _consumptions(): JsonField> = consumptions + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .consumptions() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var consumptions: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + consumptions = body.consumptions.map { it.toMutableList() } + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The credit consumptions to report (up to 1000) */ + fun consumptions(consumptions: List) = + consumptions(JsonField.of(consumptions)) + + /** + * Sets [Builder.consumptions] to an arbitrary JSON value. + * + * You should usually call [Builder.consumptions] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun consumptions(consumptions: JsonField>) = apply { + this.consumptions = consumptions.map { it.toMutableList() } + } + + /** + * Adds a single [Consumption] to [consumptions]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addConsumption(consumption: Consumption) = apply { + consumptions = + (consumptions ?: JsonField.of(mutableListOf())).also { + checkKnown("consumptions", it).add(consumption) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .consumptions() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("consumptions", consumptions).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + consumptions().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (consumptions.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + consumptions == other.consumptions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(consumptions, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{consumptions=$consumptions, additionalProperties=$additionalProperties}" + } + + /** Request body for consuming credits directly from a wallet */ + class Consumption + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val currencyId: JsonField, + private val customerId: JsonField, + private val idempotencyKey: JsonField, + private val createdAt: JsonField, + private val dimensions: JsonField, + private val resourceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("currencyId") + @ExcludeMissing + currencyId: JsonField = JsonMissing.of(), + @JsonProperty("customerId") + @ExcludeMissing + customerId: JsonField = JsonMissing.of(), + @JsonProperty("idempotencyKey") + @ExcludeMissing + idempotencyKey: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("dimensions") + @ExcludeMissing + dimensions: JsonField = JsonMissing.of(), + @JsonProperty("resourceId") + @ExcludeMissing + resourceId: JsonField = JsonMissing.of(), + ) : this( + amount, + currencyId, + customerId, + idempotencyKey, + createdAt, + dimensions, + resourceId, + mutableMapOf(), + ) + + /** + * The amount of credits to consume + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun amount(): Double = amount.getRequired("amount") + + /** + * The credit currency to consume from (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun currencyId(): String = currencyId.getRequired("currencyId") + + /** + * The customer to consume credits from (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun customerId(): String = customerId.getRequired("customerId") + + /** + * A unique key used to deduplicate the consumption (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun idempotencyKey(): String = idempotencyKey.getRequired("idempotencyKey") + + /** + * Optional timestamp the consumption is attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * Optional dimensions describing the consumption + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensions(): Optional = dimensions.getOptional("dimensions") + + /** + * Optional resource the consumption is attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun resourceId(): Optional = resourceId.getOptional("resourceId") + + /** + * 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 [currencyId]. + * + * Unlike [currencyId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currencyId") + @ExcludeMissing + fun _currencyId(): JsonField = currencyId + + /** + * Returns the raw JSON value of [customerId]. + * + * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("customerId") + @ExcludeMissing + fun _customerId(): JsonField = customerId + + /** + * Returns the raw JSON value of [idempotencyKey]. + * + * Unlike [idempotencyKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("idempotencyKey") + @ExcludeMissing + fun _idempotencyKey(): JsonField = idempotencyKey + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [dimensions]. + * + * Unlike [dimensions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dimensions") + @ExcludeMissing + fun _dimensions(): JsonField = dimensions + + /** + * Returns the raw JSON value of [resourceId]. + * + * Unlike [resourceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resourceId") + @ExcludeMissing + fun _resourceId(): JsonField = resourceId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Consumption]. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .idempotencyKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Consumption]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var currencyId: JsonField? = null + private var customerId: JsonField? = null + private var idempotencyKey: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var dimensions: JsonField = JsonMissing.of() + private var resourceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(consumption: Consumption) = apply { + amount = consumption.amount + currencyId = consumption.currencyId + customerId = consumption.customerId + idempotencyKey = consumption.idempotencyKey + createdAt = consumption.createdAt + dimensions = consumption.dimensions + resourceId = consumption.resourceId + additionalProperties = consumption.additionalProperties.toMutableMap() + } + + /** The amount of credits to consume */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** The credit currency to consume from (required) */ + fun currencyId(currencyId: String) = currencyId(JsonField.of(currencyId)) + + /** + * Sets [Builder.currencyId] to an arbitrary JSON value. + * + * You should usually call [Builder.currencyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currencyId(currencyId: JsonField) = apply { this.currencyId = currencyId } + + /** The customer to consume credits from (required) */ + fun customerId(customerId: String) = customerId(JsonField.of(customerId)) + + /** + * Sets [Builder.customerId] to an arbitrary JSON value. + * + * You should usually call [Builder.customerId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customerId(customerId: JsonField) = apply { this.customerId = customerId } + + /** A unique key used to deduplicate the consumption (required) */ + fun idempotencyKey(idempotencyKey: String) = + idempotencyKey(JsonField.of(idempotencyKey)) + + /** + * Sets [Builder.idempotencyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.idempotencyKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun idempotencyKey(idempotencyKey: JsonField) = apply { + this.idempotencyKey = idempotencyKey + } + + /** Optional timestamp the consumption is attributed to */ + 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 + } + + /** Optional dimensions describing the consumption */ + fun dimensions(dimensions: Dimensions) = dimensions(JsonField.of(dimensions)) + + /** + * Sets [Builder.dimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensions] with a well-typed [Dimensions] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dimensions(dimensions: JsonField) = apply { + this.dimensions = dimensions + } + + /** Optional resource the consumption is attributed to */ + fun resourceId(resourceId: String) = resourceId(JsonField.of(resourceId)) + + /** + * Sets [Builder.resourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun resourceId(resourceId: JsonField) = apply { this.resourceId = resourceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Consumption]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .idempotencyKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Consumption = + Consumption( + checkRequired("amount", amount), + checkRequired("currencyId", currencyId), + checkRequired("customerId", customerId), + checkRequired("idempotencyKey", idempotencyKey), + createdAt, + dimensions, + resourceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Consumption = apply { + if (validated) { + return@apply + } + + amount() + currencyId() + customerId() + idempotencyKey() + createdAt() + dimensions().ifPresent { it.validate() } + resourceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (amount.asKnown().isPresent) 1 else 0) + + (if (currencyId.asKnown().isPresent) 1 else 0) + + (if (customerId.asKnown().isPresent) 1 else 0) + + (if (idempotencyKey.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (dimensions.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceId.asKnown().isPresent) 1 else 0) + + /** Optional dimensions describing the consumption */ + class Dimensions + @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 [Dimensions]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Dimensions]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(dimensions: Dimensions) = apply { + additionalProperties = dimensions.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 [Dimensions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Dimensions = Dimensions(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Dimensions = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Dimensions && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Dimensions{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Consumption && + amount == other.amount && + currencyId == other.currencyId && + customerId == other.customerId && + idempotencyKey == other.idempotencyKey && + createdAt == other.createdAt && + dimensions == other.dimensions && + resourceId == other.resourceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + amount, + currencyId, + customerId, + idempotencyKey, + createdAt, + dimensions, + resourceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Consumption{amount=$amount, currencyId=$currencyId, customerId=$customerId, idempotencyKey=$idempotencyKey, createdAt=$createdAt, dimensions=$dimensions, resourceId=$resourceId, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ConsumptionConsumeAsyncParams && + xAccountId == other.xAccountId && + xEnvironmentId == other.xEnvironmentId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(xAccountId, xEnvironmentId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ConsumptionConsumeAsyncParams{xAccountId=$xAccountId, xEnvironmentId=$xEnvironmentId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncResponse.kt b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncResponse.kt new file mode 100644 index 00000000..37d64021 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncResponse.kt @@ -0,0 +1,170 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +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 io.stigg.core.ExcludeMissing +import io.stigg.core.JsonMissing +import io.stigg.core.JsonValue +import io.stigg.core.checkRequired +import io.stigg.errors.StiggInvalidDataException +import java.util.Collections +import java.util.Objects + +/** Response object */ +class ConsumptionConsumeAsyncResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonValue = JsonMissing.of() + ) : this(data, mutableMapOf()) + + /** + * Confirmation that the credit consumptions were accepted for processing + * + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = consumptionConsumeAsyncResponse.data().convert(MyClass.class); + * ``` + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonValue = data + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [ConsumptionConsumeAsyncResponse]. + * + * The following fields are required: + * ```java + * .data() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ConsumptionConsumeAsyncResponse]. */ + class Builder internal constructor() { + + private var data: JsonValue? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(consumptionConsumeAsyncResponse: ConsumptionConsumeAsyncResponse) = + apply { + data = consumptionConsumeAsyncResponse.data + additionalProperties = + consumptionConsumeAsyncResponse.additionalProperties.toMutableMap() + } + + /** Confirmation that the credit consumptions were accepted for processing */ + fun data(data: JsonValue) = apply { this.data = data } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ConsumptionConsumeAsyncResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionConsumeAsyncResponse = + ConsumptionConsumeAsyncResponse( + checkRequired("data", data), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its expected + * type. + */ + fun validate(): ConsumptionConsumeAsyncResponse = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = 0 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ConsumptionConsumeAsyncResponse && + data == other.data && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ConsumptionConsumeAsyncResponse{data=$data, additionalProperties=$additionalProperties}" +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeParams.kt b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeParams.kt new file mode 100644 index 00000000..1b57d459 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeParams.kt @@ -0,0 +1,1022 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +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 io.stigg.core.ExcludeMissing +import io.stigg.core.JsonField +import io.stigg.core.JsonMissing +import io.stigg.core.JsonValue +import io.stigg.core.Params +import io.stigg.core.checkRequired +import io.stigg.core.http.Headers +import io.stigg.core.http.QueryParams +import io.stigg.core.toImmutable +import io.stigg.errors.StiggInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Consumes a specified amount of credits directly from a customer wallet, with no feature mapping. + * Returns the optimistic balance. + */ +class ConsumptionConsumeParams +private constructor( + private val xAccountId: String?, + private val xEnvironmentId: String?, + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun xAccountId(): Optional = Optional.ofNullable(xAccountId) + + fun xEnvironmentId(): Optional = Optional.ofNullable(xEnvironmentId) + + /** + * The amount of credits to consume + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun amount(): Double = body.amount() + + /** + * The credit currency to consume from (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun currencyId(): String = body.currencyId() + + /** + * The customer to consume credits from (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun customerId(): String = body.customerId() + + /** + * A unique key used to deduplicate the consumption (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun idempotencyKey(): String = body.idempotencyKey() + + /** + * Optional timestamp the consumption is attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = body.createdAt() + + /** + * Optional dimensions describing the consumption + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensions(): Optional = body.dimensions() + + /** + * Optional resource the consumption is attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun resourceId(): Optional = body.resourceId() + + /** + * Returns the raw JSON value of [amount]. + * + * Unlike [amount], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _amount(): JsonField = body._amount() + + /** + * Returns the raw JSON value of [currencyId]. + * + * Unlike [currencyId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _currencyId(): JsonField = body._currencyId() + + /** + * Returns the raw JSON value of [customerId]. + * + * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _customerId(): JsonField = body._customerId() + + /** + * Returns the raw JSON value of [idempotencyKey]. + * + * Unlike [idempotencyKey], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _idempotencyKey(): JsonField = body._idempotencyKey() + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _createdAt(): JsonField = body._createdAt() + + /** + * Returns the raw JSON value of [dimensions]. + * + * Unlike [dimensions], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _dimensions(): JsonField = body._dimensions() + + /** + * Returns the raw JSON value of [resourceId]. + * + * Unlike [resourceId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _resourceId(): JsonField = body._resourceId() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ConsumptionConsumeParams]. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .idempotencyKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ConsumptionConsumeParams]. */ + class Builder internal constructor() { + + private var xAccountId: String? = null + private var xEnvironmentId: String? = null + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(consumptionConsumeParams: ConsumptionConsumeParams) = apply { + xAccountId = consumptionConsumeParams.xAccountId + xEnvironmentId = consumptionConsumeParams.xEnvironmentId + body = consumptionConsumeParams.body.toBuilder() + additionalHeaders = consumptionConsumeParams.additionalHeaders.toBuilder() + additionalQueryParams = consumptionConsumeParams.additionalQueryParams.toBuilder() + } + + fun xAccountId(xAccountId: String?) = apply { this.xAccountId = xAccountId } + + /** Alias for calling [Builder.xAccountId] with `xAccountId.orElse(null)`. */ + fun xAccountId(xAccountId: Optional) = xAccountId(xAccountId.getOrNull()) + + fun xEnvironmentId(xEnvironmentId: String?) = apply { this.xEnvironmentId = xEnvironmentId } + + /** Alias for calling [Builder.xEnvironmentId] with `xEnvironmentId.orElse(null)`. */ + fun xEnvironmentId(xEnvironmentId: Optional) = + xEnvironmentId(xEnvironmentId.getOrNull()) + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [amount] + * - [currencyId] + * - [customerId] + * - [idempotencyKey] + * - [createdAt] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** The amount of credits to consume */ + fun amount(amount: Double) = apply { body.amount(amount) } + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun amount(amount: JsonField) = apply { body.amount(amount) } + + /** The credit currency to consume from (required) */ + fun currencyId(currencyId: String) = apply { body.currencyId(currencyId) } + + /** + * Sets [Builder.currencyId] to an arbitrary JSON value. + * + * You should usually call [Builder.currencyId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun currencyId(currencyId: JsonField) = apply { body.currencyId(currencyId) } + + /** The customer to consume credits from (required) */ + fun customerId(customerId: String) = apply { body.customerId(customerId) } + + /** + * Sets [Builder.customerId] to an arbitrary JSON value. + * + * You should usually call [Builder.customerId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun customerId(customerId: JsonField) = apply { body.customerId(customerId) } + + /** A unique key used to deduplicate the consumption (required) */ + fun idempotencyKey(idempotencyKey: String) = apply { body.idempotencyKey(idempotencyKey) } + + /** + * Sets [Builder.idempotencyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.idempotencyKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun idempotencyKey(idempotencyKey: JsonField) = apply { + body.idempotencyKey(idempotencyKey) + } + + /** Optional timestamp the consumption is attributed to */ + fun createdAt(createdAt: OffsetDateTime) = apply { body.createdAt(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 { body.createdAt(createdAt) } + + /** Optional dimensions describing the consumption */ + fun dimensions(dimensions: Dimensions) = apply { body.dimensions(dimensions) } + + /** + * Sets [Builder.dimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensions] with a well-typed [Dimensions] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dimensions(dimensions: JsonField) = apply { body.dimensions(dimensions) } + + /** Optional resource the consumption is attributed to */ + fun resourceId(resourceId: String) = apply { body.resourceId(resourceId) } + + /** + * Sets [Builder.resourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun resourceId(resourceId: JsonField) = apply { body.resourceId(resourceId) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [ConsumptionConsumeParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .idempotencyKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionConsumeParams = + ConsumptionConsumeParams( + xAccountId, + xEnvironmentId, + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = + Headers.builder() + .apply { + xAccountId?.let { put("X-ACCOUNT-ID", it) } + xEnvironmentId?.let { put("X-ENVIRONMENT-ID", it) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + /** Request body for consuming credits directly from a wallet */ + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val currencyId: JsonField, + private val customerId: JsonField, + private val idempotencyKey: JsonField, + private val createdAt: JsonField, + private val dimensions: JsonField, + private val resourceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("currencyId") + @ExcludeMissing + currencyId: JsonField = JsonMissing.of(), + @JsonProperty("customerId") + @ExcludeMissing + customerId: JsonField = JsonMissing.of(), + @JsonProperty("idempotencyKey") + @ExcludeMissing + idempotencyKey: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("dimensions") + @ExcludeMissing + dimensions: JsonField = JsonMissing.of(), + @JsonProperty("resourceId") + @ExcludeMissing + resourceId: JsonField = JsonMissing.of(), + ) : this( + amount, + currencyId, + customerId, + idempotencyKey, + createdAt, + dimensions, + resourceId, + mutableMapOf(), + ) + + /** + * The amount of credits to consume + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun amount(): Double = amount.getRequired("amount") + + /** + * The credit currency to consume from (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun currencyId(): String = currencyId.getRequired("currencyId") + + /** + * The customer to consume credits from (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun customerId(): String = customerId.getRequired("customerId") + + /** + * A unique key used to deduplicate the consumption (required) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun idempotencyKey(): String = idempotencyKey.getRequired("idempotencyKey") + + /** + * Optional timestamp the consumption is attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * Optional dimensions describing the consumption + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun dimensions(): Optional = dimensions.getOptional("dimensions") + + /** + * Optional resource the consumption is attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun resourceId(): Optional = resourceId.getOptional("resourceId") + + /** + * 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 [currencyId]. + * + * Unlike [currencyId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currencyId") + @ExcludeMissing + fun _currencyId(): JsonField = currencyId + + /** + * Returns the raw JSON value of [customerId]. + * + * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("customerId") + @ExcludeMissing + fun _customerId(): JsonField = customerId + + /** + * Returns the raw JSON value of [idempotencyKey]. + * + * Unlike [idempotencyKey], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("idempotencyKey") + @ExcludeMissing + fun _idempotencyKey(): JsonField = idempotencyKey + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [dimensions]. + * + * Unlike [dimensions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("dimensions") + @ExcludeMissing + fun _dimensions(): JsonField = dimensions + + /** + * Returns the raw JSON value of [resourceId]. + * + * Unlike [resourceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resourceId") + @ExcludeMissing + fun _resourceId(): JsonField = resourceId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .idempotencyKey() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var currencyId: JsonField? = null + private var customerId: JsonField? = null + private var idempotencyKey: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var dimensions: JsonField = JsonMissing.of() + private var resourceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + amount = body.amount + currencyId = body.currencyId + customerId = body.customerId + idempotencyKey = body.idempotencyKey + createdAt = body.createdAt + dimensions = body.dimensions + resourceId = body.resourceId + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** The amount of credits to consume */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** The credit currency to consume from (required) */ + fun currencyId(currencyId: String) = currencyId(JsonField.of(currencyId)) + + /** + * Sets [Builder.currencyId] to an arbitrary JSON value. + * + * You should usually call [Builder.currencyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currencyId(currencyId: JsonField) = apply { this.currencyId = currencyId } + + /** The customer to consume credits from (required) */ + fun customerId(customerId: String) = customerId(JsonField.of(customerId)) + + /** + * Sets [Builder.customerId] to an arbitrary JSON value. + * + * You should usually call [Builder.customerId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customerId(customerId: JsonField) = apply { this.customerId = customerId } + + /** A unique key used to deduplicate the consumption (required) */ + fun idempotencyKey(idempotencyKey: String) = + idempotencyKey(JsonField.of(idempotencyKey)) + + /** + * Sets [Builder.idempotencyKey] to an arbitrary JSON value. + * + * You should usually call [Builder.idempotencyKey] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun idempotencyKey(idempotencyKey: JsonField) = apply { + this.idempotencyKey = idempotencyKey + } + + /** Optional timestamp the consumption is attributed to */ + 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 + } + + /** Optional dimensions describing the consumption */ + fun dimensions(dimensions: Dimensions) = dimensions(JsonField.of(dimensions)) + + /** + * Sets [Builder.dimensions] to an arbitrary JSON value. + * + * You should usually call [Builder.dimensions] with a well-typed [Dimensions] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun dimensions(dimensions: JsonField) = apply { + this.dimensions = dimensions + } + + /** Optional resource the consumption is attributed to */ + fun resourceId(resourceId: String) = resourceId(JsonField.of(resourceId)) + + /** + * Sets [Builder.resourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun resourceId(resourceId: JsonField) = apply { this.resourceId = resourceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .idempotencyKey() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("amount", amount), + checkRequired("currencyId", currencyId), + checkRequired("customerId", customerId), + checkRequired("idempotencyKey", idempotencyKey), + createdAt, + dimensions, + resourceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Body = apply { + if (validated) { + return@apply + } + + amount() + currencyId() + customerId() + idempotencyKey() + createdAt() + dimensions().ifPresent { it.validate() } + resourceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (amount.asKnown().isPresent) 1 else 0) + + (if (currencyId.asKnown().isPresent) 1 else 0) + + (if (customerId.asKnown().isPresent) 1 else 0) + + (if (idempotencyKey.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (dimensions.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + amount == other.amount && + currencyId == other.currencyId && + customerId == other.customerId && + idempotencyKey == other.idempotencyKey && + createdAt == other.createdAt && + dimensions == other.dimensions && + resourceId == other.resourceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + amount, + currencyId, + customerId, + idempotencyKey, + createdAt, + dimensions, + resourceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{amount=$amount, currencyId=$currencyId, customerId=$customerId, idempotencyKey=$idempotencyKey, createdAt=$createdAt, dimensions=$dimensions, resourceId=$resourceId, additionalProperties=$additionalProperties}" + } + + /** Optional dimensions describing the consumption */ + class Dimensions + @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 [Dimensions]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Dimensions]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(dimensions: Dimensions) = apply { + additionalProperties = dimensions.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 [Dimensions]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Dimensions = Dimensions(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Dimensions = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Dimensions && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Dimensions{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ConsumptionConsumeParams && + xAccountId == other.xAccountId && + xEnvironmentId == other.xEnvironmentId && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(xAccountId, xEnvironmentId, body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "ConsumptionConsumeParams{xAccountId=$xAccountId, xEnvironmentId=$xEnvironmentId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeResponse.kt b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeResponse.kt new file mode 100644 index 00000000..626842c4 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeResponse.kt @@ -0,0 +1,967 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +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 io.stigg.core.ExcludeMissing +import io.stigg.core.JsonField +import io.stigg.core.JsonMissing +import io.stigg.core.JsonValue +import io.stigg.core.checkRequired +import io.stigg.errors.StiggInvalidDataException +import java.time.OffsetDateTime +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Response object */ +class ConsumptionConsumeResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of() + ) : this(data, mutableMapOf()) + + /** + * Result of a synchronous direct credit consumption + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is unexpectedly + * missing or null (e.g. if the server responded with an unexpected value). + */ + fun data(): Data = data.getRequired("data") + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [ConsumptionConsumeResponse]. + * + * The following fields are required: + * ```java + * .data() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ConsumptionConsumeResponse]. */ + class Builder internal constructor() { + + private var data: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(consumptionConsumeResponse: ConsumptionConsumeResponse) = apply { + data = consumptionConsumeResponse.data + additionalProperties = consumptionConsumeResponse.additionalProperties.toMutableMap() + } + + /** Result of a synchronous direct credit consumption */ + fun data(data: Data) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun data(data: JsonField) = apply { this.data = data } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [ConsumptionConsumeResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .data() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ConsumptionConsumeResponse = + ConsumptionConsumeResponse( + checkRequired("data", data), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its expected + * type. + */ + fun validate(): ConsumptionConsumeResponse = apply { + if (validated) { + return@apply + } + + data().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (data.asKnown().getOrNull()?.validity() ?: 0) + + /** Result of a synchronous direct credit consumption */ + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val amount: JsonField, + private val currencyId: JsonField, + private val customerId: JsonField, + private val timestamp: JsonField, + private val credit: JsonField, + private val resourceId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("amount") @ExcludeMissing amount: JsonField = JsonMissing.of(), + @JsonProperty("currencyId") + @ExcludeMissing + currencyId: JsonField = JsonMissing.of(), + @JsonProperty("customerId") + @ExcludeMissing + customerId: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("credit") @ExcludeMissing credit: JsonField = JsonMissing.of(), + @JsonProperty("resourceId") + @ExcludeMissing + resourceId: JsonField = JsonMissing.of(), + ) : this(amount, currencyId, customerId, timestamp, credit, resourceId, mutableMapOf()) + + /** + * The amount of credits consumed + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun amount(): Double = amount.getRequired("amount") + + /** + * The credit currency the credits were consumed from + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun currencyId(): String = currencyId.getRequired("currencyId") + + /** + * The customer the credits were consumed from + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun customerId(): String = customerId.getRequired("customerId") + + /** + * The timestamp the consumption was attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * The optimistic credit balance after consumption (when sync credit consumption is enabled) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun credit(): Optional = credit.getOptional("credit") + + /** + * The resource the consumption was attributed to + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun resourceId(): Optional = resourceId.getOptional("resourceId") + + /** + * 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 [currencyId]. + * + * Unlike [currencyId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("currencyId") + @ExcludeMissing + fun _currencyId(): JsonField = currencyId + + /** + * Returns the raw JSON value of [customerId]. + * + * Unlike [customerId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("customerId") + @ExcludeMissing + fun _customerId(): JsonField = customerId + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [credit]. + * + * Unlike [credit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("credit") @ExcludeMissing fun _credit(): JsonField = credit + + /** + * Returns the raw JSON value of [resourceId]. + * + * Unlike [resourceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("resourceId") + @ExcludeMissing + fun _resourceId(): JsonField = resourceId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Data]. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .timestamp() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var amount: JsonField? = null + private var currencyId: JsonField? = null + private var customerId: JsonField? = null + private var timestamp: JsonField? = null + private var credit: JsonField = JsonMissing.of() + private var resourceId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + amount = data.amount + currencyId = data.currencyId + customerId = data.customerId + timestamp = data.timestamp + credit = data.credit + resourceId = data.resourceId + additionalProperties = data.additionalProperties.toMutableMap() + } + + /** The amount of credits consumed */ + fun amount(amount: Double) = amount(JsonField.of(amount)) + + /** + * Sets [Builder.amount] to an arbitrary JSON value. + * + * You should usually call [Builder.amount] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun amount(amount: JsonField) = apply { this.amount = amount } + + /** The credit currency the credits were consumed from */ + fun currencyId(currencyId: String) = currencyId(JsonField.of(currencyId)) + + /** + * Sets [Builder.currencyId] to an arbitrary JSON value. + * + * You should usually call [Builder.currencyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun currencyId(currencyId: JsonField) = apply { this.currencyId = currencyId } + + /** The customer the credits were consumed from */ + fun customerId(customerId: String) = customerId(JsonField.of(customerId)) + + /** + * Sets [Builder.customerId] to an arbitrary JSON value. + * + * You should usually call [Builder.customerId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun customerId(customerId: JsonField) = apply { this.customerId = customerId } + + /** The timestamp the consumption was attributed to */ + fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + /** + * The optimistic credit balance after consumption (when sync credit consumption is + * enabled) + */ + fun credit(credit: Credit?) = credit(JsonField.ofNullable(credit)) + + /** Alias for calling [Builder.credit] with `credit.orElse(null)`. */ + fun credit(credit: Optional) = credit(credit.getOrNull()) + + /** + * Sets [Builder.credit] to an arbitrary JSON value. + * + * You should usually call [Builder.credit] with a well-typed [Credit] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun credit(credit: JsonField) = apply { this.credit = credit } + + /** The resource the consumption was attributed to */ + fun resourceId(resourceId: String?) = resourceId(JsonField.ofNullable(resourceId)) + + /** Alias for calling [Builder.resourceId] with `resourceId.orElse(null)`. */ + fun resourceId(resourceId: Optional) = resourceId(resourceId.getOrNull()) + + /** + * Sets [Builder.resourceId] to an arbitrary JSON value. + * + * You should usually call [Builder.resourceId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun resourceId(resourceId: JsonField) = apply { this.resourceId = resourceId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .amount() + * .currencyId() + * .customerId() + * .timestamp() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Data = + Data( + checkRequired("amount", amount), + checkRequired("currencyId", currencyId), + checkRequired("customerId", customerId), + checkRequired("timestamp", timestamp), + credit, + resourceId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + amount() + currencyId() + customerId() + timestamp() + credit().ifPresent { it.validate() } + resourceId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (amount.asKnown().isPresent) 1 else 0) + + (if (currencyId.asKnown().isPresent) 1 else 0) + + (if (customerId.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (credit.asKnown().getOrNull()?.validity() ?: 0) + + (if (resourceId.asKnown().isPresent) 1 else 0) + + /** + * The optimistic credit balance after consumption (when sync credit consumption is enabled) + */ + class Credit + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val currencyId: JsonField, + private val currentUsage: JsonField, + private val timestamp: JsonField, + private val usageLimit: JsonField, + private val usagePeriodEnd: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("currencyId") + @ExcludeMissing + currencyId: JsonField = JsonMissing.of(), + @JsonProperty("currentUsage") + @ExcludeMissing + currentUsage: JsonField = JsonMissing.of(), + @JsonProperty("timestamp") + @ExcludeMissing + timestamp: JsonField = JsonMissing.of(), + @JsonProperty("usageLimit") + @ExcludeMissing + usageLimit: JsonField = JsonMissing.of(), + @JsonProperty("usagePeriodEnd") + @ExcludeMissing + usagePeriodEnd: JsonField = JsonMissing.of(), + ) : this( + currencyId, + currentUsage, + timestamp, + usageLimit, + usagePeriodEnd, + mutableMapOf(), + ) + + /** + * The credit currency identifier + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currencyId(): String = currencyId.getRequired("currencyId") + + /** + * The credits consumed (optimistic — includes not-yet-reconciled usage) + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun currentUsage(): Double = currentUsage.getRequired("currentUsage") + + /** + * The grant-version timestamp of this balance, used by the SDK for last-write-wins + * reconciliation + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun timestamp(): OffsetDateTime = timestamp.getRequired("timestamp") + + /** + * The total credits granted + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected + * value). + */ + fun usageLimit(): Double = usageLimit.getRequired("usageLimit") + + /** + * End of the current credit grant period (when recurring credits reset), if applicable + * + * @throws StiggInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun usagePeriodEnd(): Optional = + usagePeriodEnd.getOptional("usagePeriodEnd") + + /** + * Returns the raw JSON value of [currencyId]. + * + * Unlike [currencyId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currencyId") + @ExcludeMissing + fun _currencyId(): JsonField = currencyId + + /** + * Returns the raw JSON value of [currentUsage]. + * + * Unlike [currentUsage], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("currentUsage") + @ExcludeMissing + fun _currentUsage(): JsonField = currentUsage + + /** + * Returns the raw JSON value of [timestamp]. + * + * Unlike [timestamp], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("timestamp") + @ExcludeMissing + fun _timestamp(): JsonField = timestamp + + /** + * Returns the raw JSON value of [usageLimit]. + * + * Unlike [usageLimit], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("usageLimit") + @ExcludeMissing + fun _usageLimit(): JsonField = usageLimit + + /** + * Returns the raw JSON value of [usagePeriodEnd]. + * + * Unlike [usagePeriodEnd], this method doesn't throw if the JSON field has an + * unexpected type. + */ + @JsonProperty("usagePeriodEnd") + @ExcludeMissing + fun _usagePeriodEnd(): JsonField = usagePeriodEnd + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Credit]. + * + * The following fields are required: + * ```java + * .currencyId() + * .currentUsage() + * .timestamp() + * .usageLimit() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Credit]. */ + class Builder internal constructor() { + + private var currencyId: JsonField? = null + private var currentUsage: JsonField? = null + private var timestamp: JsonField? = null + private var usageLimit: JsonField? = null + private var usagePeriodEnd: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(credit: Credit) = apply { + currencyId = credit.currencyId + currentUsage = credit.currentUsage + timestamp = credit.timestamp + usageLimit = credit.usageLimit + usagePeriodEnd = credit.usagePeriodEnd + additionalProperties = credit.additionalProperties.toMutableMap() + } + + /** The credit currency identifier */ + fun currencyId(currencyId: String) = currencyId(JsonField.of(currencyId)) + + /** + * Sets [Builder.currencyId] to an arbitrary JSON value. + * + * You should usually call [Builder.currencyId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currencyId(currencyId: JsonField) = apply { + this.currencyId = currencyId + } + + /** The credits consumed (optimistic — includes not-yet-reconciled usage) */ + fun currentUsage(currentUsage: Double) = currentUsage(JsonField.of(currentUsage)) + + /** + * Sets [Builder.currentUsage] to an arbitrary JSON value. + * + * You should usually call [Builder.currentUsage] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun currentUsage(currentUsage: JsonField) = apply { + this.currentUsage = currentUsage + } + + /** + * The grant-version timestamp of this balance, used by the SDK for last-write-wins + * reconciliation + */ + fun timestamp(timestamp: OffsetDateTime) = timestamp(JsonField.of(timestamp)) + + /** + * Sets [Builder.timestamp] to an arbitrary JSON value. + * + * You should usually call [Builder.timestamp] with a well-typed [OffsetDateTime] + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun timestamp(timestamp: JsonField) = apply { + this.timestamp = timestamp + } + + /** The total credits granted */ + fun usageLimit(usageLimit: Double) = usageLimit(JsonField.of(usageLimit)) + + /** + * Sets [Builder.usageLimit] to an arbitrary JSON value. + * + * You should usually call [Builder.usageLimit] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun usageLimit(usageLimit: JsonField) = apply { + this.usageLimit = usageLimit + } + + /** + * End of the current credit grant period (when recurring credits reset), if + * applicable + */ + fun usagePeriodEnd(usagePeriodEnd: OffsetDateTime?) = + usagePeriodEnd(JsonField.ofNullable(usagePeriodEnd)) + + /** + * Alias for calling [Builder.usagePeriodEnd] with `usagePeriodEnd.orElse(null)`. + */ + fun usagePeriodEnd(usagePeriodEnd: Optional) = + usagePeriodEnd(usagePeriodEnd.getOrNull()) + + /** + * Sets [Builder.usagePeriodEnd] to an arbitrary JSON value. + * + * You should usually call [Builder.usagePeriodEnd] with a well-typed + * [OffsetDateTime] value instead. This method is primarily for setting the field to + * an undocumented or not yet supported value. + */ + fun usagePeriodEnd(usagePeriodEnd: JsonField) = apply { + this.usagePeriodEnd = usagePeriodEnd + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Credit]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .currencyId() + * .currentUsage() + * .timestamp() + * .usageLimit() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Credit = + Credit( + checkRequired("currencyId", currencyId), + checkRequired("currentUsage", currentUsage), + checkRequired("timestamp", timestamp), + checkRequired("usageLimit", usageLimit), + usagePeriodEnd, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing + * fields. + * + * @throws StiggInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Credit = apply { + if (validated) { + return@apply + } + + currencyId() + currentUsage() + timestamp() + usageLimit() + usagePeriodEnd() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: StiggInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (currencyId.asKnown().isPresent) 1 else 0) + + (if (currentUsage.asKnown().isPresent) 1 else 0) + + (if (timestamp.asKnown().isPresent) 1 else 0) + + (if (usageLimit.asKnown().isPresent) 1 else 0) + + (if (usagePeriodEnd.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Credit && + currencyId == other.currencyId && + currentUsage == other.currentUsage && + timestamp == other.timestamp && + usageLimit == other.usageLimit && + usagePeriodEnd == other.usagePeriodEnd && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + currencyId, + currentUsage, + timestamp, + usageLimit, + usagePeriodEnd, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Credit{currencyId=$currencyId, currentUsage=$currentUsage, timestamp=$timestamp, usageLimit=$usageLimit, usagePeriodEnd=$usagePeriodEnd, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + amount == other.amount && + currencyId == other.currencyId && + customerId == other.customerId && + timestamp == other.timestamp && + credit == other.credit && + resourceId == other.resourceId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + amount, + currencyId, + customerId, + timestamp, + credit, + resourceId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{amount=$amount, currencyId=$currencyId, customerId=$customerId, timestamp=$timestamp, credit=$credit, resourceId=$resourceId, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is ConsumptionConsumeResponse && + data == other.data && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(data, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ConsumptionConsumeResponse{data=$data, additionalProperties=$additionalProperties}" +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsync.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsync.kt index 290344e7..07c93bfd 100644 --- a/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsync.kt +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsync.kt @@ -11,6 +11,7 @@ import io.stigg.models.v1.credits.CreditGetUsageParams import io.stigg.models.v1.credits.CreditGetUsageResponse import io.stigg.models.v1.credits.CreditListLedgerPageAsync import io.stigg.models.v1.credits.CreditListLedgerParams +import io.stigg.services.async.v1.credits.ConsumptionServiceAsync import io.stigg.services.async.v1.credits.CustomCurrencyServiceAsync import io.stigg.services.async.v1.credits.GrantServiceAsync import java.util.concurrent.CompletableFuture @@ -36,6 +37,8 @@ interface CreditServiceAsync { /** Operations related to custom currencies */ fun customCurrencies(): CustomCurrencyServiceAsync + fun consumption(): ConsumptionServiceAsync + /** * Retrieves the automatic recharge configuration for a customer and currency. Returns default * settings if no configuration exists. @@ -94,6 +97,8 @@ interface CreditServiceAsync { /** Operations related to custom currencies */ fun customCurrencies(): CustomCurrencyServiceAsync.WithRawResponse + fun consumption(): ConsumptionServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `get /api/v1/credits/auto-recharge`, but is otherwise the * same as [CreditServiceAsync.getAutoRecharge]. diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsyncImpl.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsyncImpl.kt index 516f735a..6d9057a1 100644 --- a/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsyncImpl.kt +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/CreditServiceAsyncImpl.kt @@ -21,6 +21,8 @@ import io.stigg.models.v1.credits.CreditGetUsageResponse import io.stigg.models.v1.credits.CreditListLedgerPageAsync import io.stigg.models.v1.credits.CreditListLedgerPageResponse import io.stigg.models.v1.credits.CreditListLedgerParams +import io.stigg.services.async.v1.credits.ConsumptionServiceAsync +import io.stigg.services.async.v1.credits.ConsumptionServiceAsyncImpl import io.stigg.services.async.v1.credits.CustomCurrencyServiceAsync import io.stigg.services.async.v1.credits.CustomCurrencyServiceAsyncImpl import io.stigg.services.async.v1.credits.GrantServiceAsync @@ -41,6 +43,10 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli CustomCurrencyServiceAsyncImpl(clientOptions) } + private val consumption: ConsumptionServiceAsync by lazy { + ConsumptionServiceAsyncImpl(clientOptions) + } + override fun withRawResponse(): CreditServiceAsync.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): CreditServiceAsync = @@ -52,6 +58,8 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli /** Operations related to custom currencies */ override fun customCurrencies(): CustomCurrencyServiceAsync = customCurrencies + override fun consumption(): ConsumptionServiceAsync = consumption + override fun getAutoRecharge( params: CreditGetAutoRechargeParams, requestOptions: RequestOptions, @@ -87,6 +95,10 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli CustomCurrencyServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val consumption: ConsumptionServiceAsync.WithRawResponse by lazy { + ConsumptionServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): CreditServiceAsync.WithRawResponse = @@ -101,6 +113,8 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun customCurrencies(): CustomCurrencyServiceAsync.WithRawResponse = customCurrencies + override fun consumption(): ConsumptionServiceAsync.WithRawResponse = consumption + private val getAutoRechargeHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsync.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsync.kt new file mode 100644 index 00000000..5c971760 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsync.kt @@ -0,0 +1,102 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.services.async.v1.credits + +import io.stigg.core.ClientOptions +import io.stigg.core.RequestOptions +import io.stigg.core.http.HttpResponseFor +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncResponse +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface ConsumptionServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ConsumptionServiceAsync + + /** + * Consumes a specified amount of credits directly from a customer wallet, with no feature + * mapping. Returns the optimistic balance. + */ + fun consume(params: ConsumptionConsumeParams): CompletableFuture = + consume(params, RequestOptions.none()) + + /** @see consume */ + fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Consumes credits directly from customer wallets asynchronously. Consumptions are reconciled + * asynchronously into the credit balances. + */ + fun consumeAsync( + params: ConsumptionConsumeAsyncParams + ): CompletableFuture = + consumeAsync(params, RequestOptions.none()) + + /** @see consumeAsync */ + fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [ConsumptionServiceAsync] that provides access to raw HTTP responses for each + * method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ConsumptionServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/credits/consumption`, but is otherwise the + * same as [ConsumptionServiceAsync.consume]. + */ + fun consume( + params: ConsumptionConsumeParams + ): CompletableFuture> = + consume(params, RequestOptions.none()) + + /** @see consume */ + fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post /api/v1/credits/consumption/async`, but is + * otherwise the same as [ConsumptionServiceAsync.consumeAsync]. + */ + fun consumeAsync( + params: ConsumptionConsumeAsyncParams + ): CompletableFuture> = + consumeAsync(params, RequestOptions.none()) + + /** @see consumeAsync */ + fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsyncImpl.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsyncImpl.kt new file mode 100644 index 00000000..e4ee5f3d --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsyncImpl.kt @@ -0,0 +1,126 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.services.async.v1.credits + +import io.stigg.core.ClientOptions +import io.stigg.core.RequestOptions +import io.stigg.core.handlers.errorBodyHandler +import io.stigg.core.handlers.errorHandler +import io.stigg.core.handlers.jsonHandler +import io.stigg.core.http.HttpMethod +import io.stigg.core.http.HttpRequest +import io.stigg.core.http.HttpResponse +import io.stigg.core.http.HttpResponse.Handler +import io.stigg.core.http.HttpResponseFor +import io.stigg.core.http.json +import io.stigg.core.http.parseable +import io.stigg.core.prepareAsync +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncResponse +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +class ConsumptionServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + ConsumptionServiceAsync { + + private val withRawResponse: ConsumptionServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ConsumptionServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ConsumptionServiceAsync = + ConsumptionServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/credits/consumption + withRawResponse().consume(params, requestOptions).thenApply { it.parse() } + + override fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/credits/consumption/async + withRawResponse().consumeAsync(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ConsumptionServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ConsumptionServiceAsync.WithRawResponse = + ConsumptionServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val consumeHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "credits", "consumption") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { consumeHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val consumeAsyncHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "credits", "consumption", "async") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { consumeAsyncHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditService.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditService.kt index 2046a645..6c1a7d7a 100644 --- a/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditService.kt +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditService.kt @@ -12,6 +12,7 @@ import io.stigg.models.v1.credits.CreditGetUsageParams import io.stigg.models.v1.credits.CreditGetUsageResponse import io.stigg.models.v1.credits.CreditListLedgerPage import io.stigg.models.v1.credits.CreditListLedgerParams +import io.stigg.services.blocking.v1.credits.ConsumptionService import io.stigg.services.blocking.v1.credits.CustomCurrencyService import io.stigg.services.blocking.v1.credits.GrantService import java.util.function.Consumer @@ -36,6 +37,8 @@ interface CreditService { /** Operations related to custom currencies */ fun customCurrencies(): CustomCurrencyService + fun consumption(): ConsumptionService + /** * Retrieves the automatic recharge configuration for a customer and currency. Returns default * settings if no configuration exists. @@ -88,6 +91,8 @@ interface CreditService { /** Operations related to custom currencies */ fun customCurrencies(): CustomCurrencyService.WithRawResponse + fun consumption(): ConsumptionService.WithRawResponse + /** * Returns a raw HTTP response for `get /api/v1/credits/auto-recharge`, but is otherwise the * same as [CreditService.getAutoRecharge]. diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditServiceImpl.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditServiceImpl.kt index 5c3eee64..a2303964 100644 --- a/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditServiceImpl.kt +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/CreditServiceImpl.kt @@ -21,6 +21,8 @@ import io.stigg.models.v1.credits.CreditGetUsageResponse import io.stigg.models.v1.credits.CreditListLedgerPage import io.stigg.models.v1.credits.CreditListLedgerPageResponse import io.stigg.models.v1.credits.CreditListLedgerParams +import io.stigg.services.blocking.v1.credits.ConsumptionService +import io.stigg.services.blocking.v1.credits.ConsumptionServiceImpl import io.stigg.services.blocking.v1.credits.CustomCurrencyService import io.stigg.services.blocking.v1.credits.CustomCurrencyServiceImpl import io.stigg.services.blocking.v1.credits.GrantService @@ -40,6 +42,8 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp CustomCurrencyServiceImpl(clientOptions) } + private val consumption: ConsumptionService by lazy { ConsumptionServiceImpl(clientOptions) } + override fun withRawResponse(): CreditService.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): CreditService = @@ -51,6 +55,8 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp /** Operations related to custom currencies */ override fun customCurrencies(): CustomCurrencyService = customCurrencies + override fun consumption(): ConsumptionService = consumption + override fun getAutoRecharge( params: CreditGetAutoRechargeParams, requestOptions: RequestOptions, @@ -86,6 +92,10 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp CustomCurrencyServiceImpl.WithRawResponseImpl(clientOptions) } + private val consumption: ConsumptionService.WithRawResponse by lazy { + ConsumptionServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): CreditService.WithRawResponse = @@ -99,6 +109,8 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp /** Operations related to custom currencies */ override fun customCurrencies(): CustomCurrencyService.WithRawResponse = customCurrencies + override fun consumption(): ConsumptionService.WithRawResponse = consumption + private val getAutoRechargeHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionService.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionService.kt new file mode 100644 index 00000000..0e8df789 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionService.kt @@ -0,0 +1,101 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.services.blocking.v1.credits + +import com.google.errorprone.annotations.MustBeClosed +import io.stigg.core.ClientOptions +import io.stigg.core.RequestOptions +import io.stigg.core.http.HttpResponseFor +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncResponse +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeResponse +import java.util.function.Consumer + +interface ConsumptionService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): ConsumptionService + + /** + * Consumes a specified amount of credits directly from a customer wallet, with no feature + * mapping. Returns the optimistic balance. + */ + fun consume(params: ConsumptionConsumeParams): ConsumptionConsumeResponse = + consume(params, RequestOptions.none()) + + /** @see consume */ + fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ConsumptionConsumeResponse + + /** + * Consumes credits directly from customer wallets asynchronously. Consumptions are reconciled + * asynchronously into the credit balances. + */ + fun consumeAsync(params: ConsumptionConsumeAsyncParams): ConsumptionConsumeAsyncResponse = + consumeAsync(params, RequestOptions.none()) + + /** @see consumeAsync */ + fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): ConsumptionConsumeAsyncResponse + + /** + * A view of [ConsumptionService] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): ConsumptionService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/credits/consumption`, but is otherwise the + * same as [ConsumptionService.consume]. + */ + @MustBeClosed + fun consume(params: ConsumptionConsumeParams): HttpResponseFor = + consume(params, RequestOptions.none()) + + /** @see consume */ + @MustBeClosed + fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post /api/v1/credits/consumption/async`, but is + * otherwise the same as [ConsumptionService.consumeAsync]. + */ + @MustBeClosed + fun consumeAsync( + params: ConsumptionConsumeAsyncParams + ): HttpResponseFor = + consumeAsync(params, RequestOptions.none()) + + /** @see consumeAsync */ + @MustBeClosed + fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionServiceImpl.kt b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionServiceImpl.kt new file mode 100644 index 00000000..33566198 --- /dev/null +++ b/stigg-java-core/src/main/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionServiceImpl.kt @@ -0,0 +1,119 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.services.blocking.v1.credits + +import io.stigg.core.ClientOptions +import io.stigg.core.RequestOptions +import io.stigg.core.handlers.errorBodyHandler +import io.stigg.core.handlers.errorHandler +import io.stigg.core.handlers.jsonHandler +import io.stigg.core.http.HttpMethod +import io.stigg.core.http.HttpRequest +import io.stigg.core.http.HttpResponse +import io.stigg.core.http.HttpResponse.Handler +import io.stigg.core.http.HttpResponseFor +import io.stigg.core.http.json +import io.stigg.core.http.parseable +import io.stigg.core.prepare +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncResponse +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeResponse +import java.util.function.Consumer + +class ConsumptionServiceImpl internal constructor(private val clientOptions: ClientOptions) : + ConsumptionService { + + private val withRawResponse: ConsumptionService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): ConsumptionService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): ConsumptionService = + ConsumptionServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions, + ): ConsumptionConsumeResponse = + // post /api/v1/credits/consumption + withRawResponse().consume(params, requestOptions).parse() + + override fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions, + ): ConsumptionConsumeAsyncResponse = + // post /api/v1/credits/consumption/async + withRawResponse().consumeAsync(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + ConsumptionService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): ConsumptionService.WithRawResponse = + ConsumptionServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val consumeHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun consume( + params: ConsumptionConsumeParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "credits", "consumption") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { consumeHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val consumeAsyncHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun consumeAsync( + params: ConsumptionConsumeAsyncParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "credits", "consumption", "async") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { consumeAsyncHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncParamsTest.kt b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncParamsTest.kt new file mode 100644 index 00000000..05fa1fd3 --- /dev/null +++ b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncParamsTest.kt @@ -0,0 +1,158 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +import io.stigg.core.JsonValue +import io.stigg.core.http.Headers +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ConsumptionConsumeAsyncParamsTest { + + @Test + fun create() { + ConsumptionConsumeAsyncParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeAsyncParams.Consumption.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + } + + @Test + fun headers() { + val params = + ConsumptionConsumeAsyncParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeAsyncParams.Consumption.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder() + .put("X-ACCOUNT-ID", "X-ACCOUNT-ID") + .put("X-ENVIRONMENT-ID", "X-ENVIRONMENT-ID") + .build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + ConsumptionConsumeAsyncParams.builder() + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .build() + ) + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } + + @Test + fun body() { + val params = + ConsumptionConsumeAsyncParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeAsyncParams.Consumption.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + + val body = params._body() + + assertThat(body.consumptions()) + .containsExactly( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeAsyncParams.Consumption.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + ConsumptionConsumeAsyncParams.builder() + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .build() + ) + .build() + + val body = params._body() + + assertThat(body.consumptions()) + .containsExactly( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .build() + ) + } +} diff --git a/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncResponseTest.kt b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncResponseTest.kt new file mode 100644 index 00000000..fbb88147 --- /dev/null +++ b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeAsyncResponseTest.kt @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import io.stigg.core.JsonValue +import io.stigg.core.jsonMapper +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ConsumptionConsumeAsyncResponseTest { + + @Test + fun create() { + val consumptionConsumeAsyncResponse = + ConsumptionConsumeAsyncResponse.builder() + .data(JsonValue.from(mapOf())) + .build() + + assertThat(consumptionConsumeAsyncResponse._data()) + .isEqualTo(JsonValue.from(mapOf())) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val consumptionConsumeAsyncResponse = + ConsumptionConsumeAsyncResponse.builder() + .data(JsonValue.from(mapOf())) + .build() + + val roundtrippedConsumptionConsumeAsyncResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(consumptionConsumeAsyncResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConsumptionConsumeAsyncResponse) + .isEqualTo(consumptionConsumeAsyncResponse) + } +} diff --git a/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeParamsTest.kt b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeParamsTest.kt new file mode 100644 index 00000000..04df54aa --- /dev/null +++ b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeParamsTest.kt @@ -0,0 +1,129 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +import io.stigg.core.JsonValue +import io.stigg.core.http.Headers +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ConsumptionConsumeParamsTest { + + @Test + fun create() { + ConsumptionConsumeParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeParams.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + } + + @Test + fun headers() { + val params = + ConsumptionConsumeParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeParams.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder() + .put("X-ACCOUNT-ID", "X-ACCOUNT-ID") + .put("X-ENVIRONMENT-ID", "X-ENVIRONMENT-ID") + .build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + ConsumptionConsumeParams.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } + + @Test + fun body() { + val params = + ConsumptionConsumeParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeParams.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + + val body = params._body() + + assertThat(body.amount()).isEqualTo(1.0) + assertThat(body.currencyId()).isEqualTo("currencyId") + assertThat(body.customerId()).isEqualTo("customerId") + assertThat(body.idempotencyKey()).isEqualTo("x") + assertThat(body.createdAt()).contains(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + assertThat(body.dimensions()) + .contains( + ConsumptionConsumeParams.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + assertThat(body.resourceId()).contains("resourceId") + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + ConsumptionConsumeParams.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .build() + + val body = params._body() + + assertThat(body.amount()).isEqualTo(1.0) + assertThat(body.currencyId()).isEqualTo("currencyId") + assertThat(body.customerId()).isEqualTo("customerId") + assertThat(body.idempotencyKey()).isEqualTo("x") + } +} diff --git a/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeResponseTest.kt b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeResponseTest.kt new file mode 100644 index 00000000..ef5d5f0b --- /dev/null +++ b/stigg-java-core/src/test/kotlin/io/stigg/models/v1/credits/consumption/ConsumptionConsumeResponseTest.kt @@ -0,0 +1,91 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.models.v1.credits.consumption + +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import io.stigg.core.jsonMapper +import java.time.OffsetDateTime +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class ConsumptionConsumeResponseTest { + + @Test + fun create() { + val consumptionConsumeResponse = + ConsumptionConsumeResponse.builder() + .data( + ConsumptionConsumeResponse.Data.builder() + .amount(0.0) + .currencyId("currencyId") + .customerId("customerId") + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .credit( + ConsumptionConsumeResponse.Data.Credit.builder() + .currencyId("currencyId") + .currentUsage(0.0) + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .usageLimit(0.0) + .usagePeriodEnd(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + + assertThat(consumptionConsumeResponse.data()) + .isEqualTo( + ConsumptionConsumeResponse.Data.builder() + .amount(0.0) + .currencyId("currencyId") + .customerId("customerId") + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .credit( + ConsumptionConsumeResponse.Data.Credit.builder() + .currencyId("currencyId") + .currentUsage(0.0) + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .usageLimit(0.0) + .usagePeriodEnd(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .resourceId("resourceId") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val consumptionConsumeResponse = + ConsumptionConsumeResponse.builder() + .data( + ConsumptionConsumeResponse.Data.builder() + .amount(0.0) + .currencyId("currencyId") + .customerId("customerId") + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .credit( + ConsumptionConsumeResponse.Data.Credit.builder() + .currencyId("currencyId") + .currentUsage(0.0) + .timestamp(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .usageLimit(0.0) + .usagePeriodEnd(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + + val roundtrippedConsumptionConsumeResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(consumptionConsumeResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedConsumptionConsumeResponse).isEqualTo(consumptionConsumeResponse) + } +} diff --git a/stigg-java-core/src/test/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsyncTest.kt b/stigg-java-core/src/test/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsyncTest.kt new file mode 100644 index 00000000..39ac9691 --- /dev/null +++ b/stigg-java-core/src/test/kotlin/io/stigg/services/async/v1/credits/ConsumptionServiceAsyncTest.kt @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.services.async.v1.credits + +import io.stigg.client.okhttp.StiggOkHttpClientAsync +import io.stigg.core.JsonValue +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeParams +import java.time.OffsetDateTime +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class ConsumptionServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun consume() { + val client = StiggOkHttpClientAsync.builder().apiKey("My API Key").build() + val consumptionServiceAsync = client.v1().credits().consumption() + + val responseFuture = + consumptionServiceAsync.consume( + ConsumptionConsumeParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeParams.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + + val response = responseFuture.get() + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun consumeAsync() { + val client = StiggOkHttpClientAsync.builder().apiKey("My API Key").build() + val consumptionServiceAsync = client.v1().credits().consumption() + + val responseFuture = + consumptionServiceAsync.consumeAsync( + ConsumptionConsumeAsyncParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeAsyncParams.Consumption.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + ) + + val response = responseFuture.get() + response.validate() + } +} diff --git a/stigg-java-core/src/test/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionServiceTest.kt b/stigg-java-core/src/test/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionServiceTest.kt new file mode 100644 index 00000000..c9150dd8 --- /dev/null +++ b/stigg-java-core/src/test/kotlin/io/stigg/services/blocking/v1/credits/ConsumptionServiceTest.kt @@ -0,0 +1,74 @@ +// File generated from our OpenAPI spec by Stainless. + +package io.stigg.services.blocking.v1.credits + +import io.stigg.client.okhttp.StiggOkHttpClient +import io.stigg.core.JsonValue +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeAsyncParams +import io.stigg.models.v1.credits.consumption.ConsumptionConsumeParams +import java.time.OffsetDateTime +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class ConsumptionServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun consume() { + val client = StiggOkHttpClient.builder().apiKey("My API Key").build() + val consumptionService = client.v1().credits().consumption() + + val response = + consumptionService.consume( + ConsumptionConsumeParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeParams.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + + response.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun consumeAsync() { + val client = StiggOkHttpClient.builder().apiKey("My API Key").build() + val consumptionService = client.v1().credits().consumption() + + val response = + consumptionService.consumeAsync( + ConsumptionConsumeAsyncParams.builder() + .xAccountId("X-ACCOUNT-ID") + .xEnvironmentId("X-ENVIRONMENT-ID") + .addConsumption( + ConsumptionConsumeAsyncParams.Consumption.builder() + .amount(1.0) + .currencyId("currencyId") + .customerId("customerId") + .idempotencyKey("x") + .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) + .dimensions( + ConsumptionConsumeAsyncParams.Consumption.Dimensions.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .resourceId("resourceId") + .build() + ) + .build() + ) + + response.validate() + } +}