From d24a5fa945a0d03149a2b3bddcd6f1b68419cd12 Mon Sep 17 00:00:00 2001 From: cb-hareeshv Date: Mon, 28 Sep 2026 12:01:42 +0530 Subject: [PATCH] Add the settings preference client to the Java v4 SDK. Expose list and upsert for /preferences, plus preference definitions, including the billing_rules setting group. Co-authored-by: Cursor --- .../chargebee/v4/client/ClientMethods.java | 18 + .../v4/client/ClientMethodsImpl.java | 14 + .../chargebee/v4/client/ServiceRegistry.java | 38 + .../v4/models/preference/Preference.java | 375 ++++++ .../params/PreferenceListParams.java | 205 +++ .../params/PreferenceUpsertParams.java | 200 +++ .../responses/PreferenceListResponse.java | 99 ++ .../responses/PreferenceUpsertResponse.java | 99 ++ .../PreferenceDefinition.java | 1185 +++++++++++++++++ ...erenceDefinitionListDefinitionsParams.java | 209 +++ ...enceDefinitionListDefinitionsResponse.java | 108 ++ .../services/PreferenceDefinitionService.java | 100 ++ .../v4/services/PreferenceService.java | 113 ++ 13 files changed, 2763 insertions(+) create mode 100644 src/main/java/com/chargebee/v4/models/preference/Preference.java create mode 100644 src/main/java/com/chargebee/v4/models/preference/params/PreferenceListParams.java create mode 100644 src/main/java/com/chargebee/v4/models/preference/params/PreferenceUpsertParams.java create mode 100644 src/main/java/com/chargebee/v4/models/preference/responses/PreferenceListResponse.java create mode 100644 src/main/java/com/chargebee/v4/models/preference/responses/PreferenceUpsertResponse.java create mode 100644 src/main/java/com/chargebee/v4/models/preferenceDefinition/PreferenceDefinition.java create mode 100644 src/main/java/com/chargebee/v4/models/preferenceDefinition/params/PreferenceDefinitionListDefinitionsParams.java create mode 100644 src/main/java/com/chargebee/v4/models/preferenceDefinition/responses/PreferenceDefinitionListDefinitionsResponse.java create mode 100644 src/main/java/com/chargebee/v4/services/PreferenceDefinitionService.java create mode 100644 src/main/java/com/chargebee/v4/services/PreferenceService.java diff --git a/src/main/java/com/chargebee/v4/client/ClientMethods.java b/src/main/java/com/chargebee/v4/client/ClientMethods.java index 906516fb..3ae63740 100644 --- a/src/main/java/com/chargebee/v4/client/ClientMethods.java +++ b/src/main/java/com/chargebee/v4/client/ClientMethods.java @@ -28,6 +28,8 @@ import com.chargebee.v4.services.ItemService; +import com.chargebee.v4.services.PreferenceService; + import com.chargebee.v4.services.RampService; import com.chargebee.v4.services.OmnichannelOneTimeOrderService; @@ -74,6 +76,8 @@ import com.chargebee.v4.services.ProductService; +import com.chargebee.v4.services.PreferenceDefinitionService; + import com.chargebee.v4.services.CouponCodeService; import com.chargebee.v4.services.AddressService; @@ -304,6 +308,13 @@ public interface ClientMethods { */ ItemService items(); + /** + * Access preference-related operations. + * + * @return PreferenceService instance for fluent API access + */ + PreferenceService preferences(); + /** * Access ramp-related operations. * @@ -465,6 +476,13 @@ public interface ClientMethods { */ ProductService products(); + /** + * Access preference_definition-related operations. + * + * @return PreferenceDefinitionService instance for fluent API access + */ + PreferenceDefinitionService preferenceDefinitions(); + /** * Access coupon_code-related operations. * diff --git a/src/main/java/com/chargebee/v4/client/ClientMethodsImpl.java b/src/main/java/com/chargebee/v4/client/ClientMethodsImpl.java index 328d0b6d..dc548404 100644 --- a/src/main/java/com/chargebee/v4/client/ClientMethodsImpl.java +++ b/src/main/java/com/chargebee/v4/client/ClientMethodsImpl.java @@ -28,6 +28,8 @@ import com.chargebee.v4.services.ItemService; +import com.chargebee.v4.services.PreferenceService; + import com.chargebee.v4.services.RampService; import com.chargebee.v4.services.OmnichannelOneTimeOrderService; @@ -74,6 +76,8 @@ import com.chargebee.v4.services.ProductService; +import com.chargebee.v4.services.PreferenceDefinitionService; + import com.chargebee.v4.services.CouponCodeService; import com.chargebee.v4.services.AddressService; @@ -278,6 +282,11 @@ public ItemService items() { return getServiceRegistry().items(); } + @Override + public PreferenceService preferences() { + return getServiceRegistry().preferences(); + } + @Override public RampService ramps() { return getServiceRegistry().ramps(); @@ -393,6 +402,11 @@ public ProductService products() { return getServiceRegistry().products(); } + @Override + public PreferenceDefinitionService preferenceDefinitions() { + return getServiceRegistry().preferenceDefinitions(); + } + @Override public CouponCodeService couponCodes() { return getServiceRegistry().couponCodes(); diff --git a/src/main/java/com/chargebee/v4/client/ServiceRegistry.java b/src/main/java/com/chargebee/v4/client/ServiceRegistry.java index df2eddf5..3dff5ca5 100644 --- a/src/main/java/com/chargebee/v4/client/ServiceRegistry.java +++ b/src/main/java/com/chargebee/v4/client/ServiceRegistry.java @@ -28,6 +28,8 @@ import com.chargebee.v4.services.ItemService; +import com.chargebee.v4.services.PreferenceService; + import com.chargebee.v4.services.RampService; import com.chargebee.v4.services.OmnichannelOneTimeOrderService; @@ -74,6 +76,8 @@ import com.chargebee.v4.services.ProductService; +import com.chargebee.v4.services.PreferenceDefinitionService; + import com.chargebee.v4.services.CouponCodeService; import com.chargebee.v4.services.AddressService; @@ -235,6 +239,8 @@ final class ServiceRegistry { private volatile ItemService itemService; + private volatile PreferenceService preferenceService; + private volatile RampService rampService; private volatile OmnichannelOneTimeOrderService omnichannelOneTimeOrderService; @@ -281,6 +287,8 @@ final class ServiceRegistry { private volatile ProductService productService; + private volatile PreferenceDefinitionService preferenceDefinitionService; + private volatile CouponCodeService couponCodeService; private volatile AddressService addressService; @@ -621,6 +629,21 @@ ItemService items() { return itemService; } + /** + * Get or create the PreferenceService instance. Thread-safe lazy initialization using + * double-checked locking. + */ + PreferenceService preferences() { + if (preferenceService == null) { + synchronized (this) { + if (preferenceService == null) { + preferenceService = new PreferenceService(client); + } + } + } + return preferenceService; + } + /** * Get or create the RampService instance. Thread-safe lazy initialization using double-checked * locking. @@ -966,6 +989,21 @@ ProductService products() { return productService; } + /** + * Get or create the PreferenceDefinitionService instance. Thread-safe lazy initialization using + * double-checked locking. + */ + PreferenceDefinitionService preferenceDefinitions() { + if (preferenceDefinitionService == null) { + synchronized (this) { + if (preferenceDefinitionService == null) { + preferenceDefinitionService = new PreferenceDefinitionService(client); + } + } + } + return preferenceDefinitionService; + } + /** * Get or create the CouponCodeService instance. Thread-safe lazy initialization using * double-checked locking. diff --git a/src/main/java/com/chargebee/v4/models/preference/Preference.java b/src/main/java/com/chargebee/v4/models/preference/Preference.java new file mode 100644 index 00000000..8abe9bcb --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preference/Preference.java @@ -0,0 +1,375 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ + +package com.chargebee.v4.models.preference; + +import com.chargebee.v4.internal.JsonUtil; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.sql.Timestamp; +import java.util.List; + +public class Preference { + + private String id; + private SettingGroup settingGroup; + private String value; + private Boolean allowOverrideInInterface; + private Boolean allowOverrideInApi; + private Timestamp createdAt; + private Timestamp updatedAt; + private List variants; + + public String getId() { + return id; + } + + public SettingGroup getSettingGroup() { + return settingGroup; + } + + public String getValue() { + return value; + } + + public Boolean getAllowOverrideInInterface() { + return allowOverrideInInterface; + } + + public Boolean getAllowOverrideInApi() { + return allowOverrideInApi; + } + + public Timestamp getCreatedAt() { + return createdAt; + } + + public Timestamp getUpdatedAt() { + return updatedAt; + } + + public List getVariants() { + return variants; + } + + public enum SettingGroup { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroup was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroup(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroup fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroup enumValue : SettingGroup.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static Preference fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static Preference fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static Preference fromJson(JsonObject jsonObj) { + Preference obj = new Preference(); + + obj.id = JsonUtil.getString(jsonObj, "id"); + + obj.settingGroup = SettingGroup.fromString(JsonUtil.getString(jsonObj, "setting_group")); + + obj.value = JsonUtil.getString(jsonObj, "value"); + + obj.allowOverrideInInterface = JsonUtil.getBoolean(jsonObj, "allow_override_in_interface"); + + obj.allowOverrideInApi = JsonUtil.getBoolean(jsonObj, "allow_override_in_api"); + + obj.createdAt = JsonUtil.getTimestamp(jsonObj, "created_at"); + + obj.updatedAt = JsonUtil.getTimestamp(jsonObj, "updated_at"); + + obj.variants = + JsonUtil.mapArray(JsonUtil.getJsonArray(jsonObj, "variants"), Variants::fromJson); + + return obj; + } + + @Override + public String toString() { + return "Preference{" + + "id=" + + id + + ", settingGroup=" + + settingGroup + + ", value=" + + value + + ", allowOverrideInInterface=" + + allowOverrideInInterface + + ", allowOverrideInApi=" + + allowOverrideInApi + + ", createdAt=" + + createdAt + + ", updatedAt=" + + updatedAt + + ", variants=" + + variants + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Preference that = (Preference) o; + return java.util.Objects.equals(id, that.id) + && java.util.Objects.equals(settingGroup, that.settingGroup) + && java.util.Objects.equals(value, that.value) + && java.util.Objects.equals(allowOverrideInInterface, that.allowOverrideInInterface) + && java.util.Objects.equals(allowOverrideInApi, that.allowOverrideInApi) + && java.util.Objects.equals(createdAt, that.createdAt) + && java.util.Objects.equals(updatedAt, that.updatedAt) + && java.util.Objects.equals(variants, that.variants); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash( + id, + settingGroup, + value, + allowOverrideInInterface, + allowOverrideInApi, + createdAt, + updatedAt, + variants); + } + + public static class Variants { + + private String value; + private Boolean allowOverrideInInterface; + private Boolean allowOverrideInApi; + private List criteria; + + public String getValue() { + return value; + } + + public Boolean getAllowOverrideInInterface() { + return allowOverrideInInterface; + } + + public Boolean getAllowOverrideInApi() { + return allowOverrideInApi; + } + + public List getCriteria() { + return criteria; + } + + public static Variants fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static Variants fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static Variants fromJson(JsonObject jsonObj) { + Variants obj = new Variants(); + + obj.value = JsonUtil.getString(jsonObj, "value"); + + obj.allowOverrideInInterface = JsonUtil.getBoolean(jsonObj, "allow_override_in_interface"); + + obj.allowOverrideInApi = JsonUtil.getBoolean(jsonObj, "allow_override_in_api"); + + obj.criteria = + JsonUtil.mapArray(JsonUtil.getJsonArray(jsonObj, "criteria"), Criteria::fromJson); + + return obj; + } + + @Override + public String toString() { + return "Variants{" + + "value=" + + value + + ", allowOverrideInInterface=" + + allowOverrideInInterface + + ", allowOverrideInApi=" + + allowOverrideInApi + + ", criteria=" + + criteria + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Variants that = (Variants) o; + return java.util.Objects.equals(value, that.value) + && java.util.Objects.equals(allowOverrideInInterface, that.allowOverrideInInterface) + && java.util.Objects.equals(allowOverrideInApi, that.allowOverrideInApi) + && java.util.Objects.equals(criteria, that.criteria); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(value, allowOverrideInInterface, allowOverrideInApi, criteria); + } + + public static class Criteria { + + private Operand operand; + private Operator operator; + private List values; + + public Operand getOperand() { + return operand; + } + + public Operator getOperator() { + return operator; + } + + public List getValues() { + return values; + } + + public enum Operand { + REQUEST_SOURCE("request_source"), + + /** An enum member indicating that Operand was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Operand(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Operand fromString(String value) { + if (value == null) return _UNKNOWN; + for (Operand enumValue : Operand.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum Operator { + IS("is"), + + IN("in"), + + /** An enum member indicating that Operator was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Operator(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Operator fromString(String value) { + if (value == null) return _UNKNOWN; + for (Operator enumValue : Operator.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static Criteria fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static Criteria fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static Criteria fromJson(JsonObject jsonObj) { + Criteria obj = new Criteria(); + + obj.operand = Operand.fromString(JsonUtil.getString(jsonObj, "operand")); + + obj.operator = Operator.fromString(JsonUtil.getString(jsonObj, "operator")); + + JsonArray __valuesArr = JsonUtil.getJsonArray(jsonObj, "values"); + if (__valuesArr != null) { + obj.values = JsonUtil.parseArrayOfString(__valuesArr); + } + + return obj; + } + + @Override + public String toString() { + return "Criteria{" + + "operand=" + + operand + + ", operator=" + + operator + + ", values=" + + values + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Criteria that = (Criteria) o; + return java.util.Objects.equals(operand, that.operand) + && java.util.Objects.equals(operator, that.operator) + && java.util.Objects.equals(values, that.values); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(operand, operator, values); + } + } + } +} diff --git a/src/main/java/com/chargebee/v4/models/preference/params/PreferenceListParams.java b/src/main/java/com/chargebee/v4/models/preference/params/PreferenceListParams.java new file mode 100644 index 00000000..f9a147c0 --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preference/params/PreferenceListParams.java @@ -0,0 +1,205 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ + +package com.chargebee.v4.models.preference.params; + +import com.chargebee.v4.internal.Recommended; +import com.chargebee.v4.filters.EnumFilter; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +public final class PreferenceListParams { + + private final Map queryParams; + + private PreferenceListParams(PreferenceListBuilder builder) { + this.queryParams = Collections.unmodifiableMap(new LinkedHashMap<>(builder.queryParams)); + } + + /** Get the query parameters for this request. */ + public Map toQueryParams() { + return queryParams; + } + + public PreferenceListBuilder toBuilder() { + PreferenceListBuilder builder = new PreferenceListBuilder(); + builder.queryParams.putAll(queryParams); + return builder; + } + + /** Create a new builder for PreferenceListParams. */ + @Recommended(reason = "Preferred for reusability, validation, and LLM-friendliness") + public static PreferenceListBuilder builder() { + return new PreferenceListBuilder(); + } + + public static final class PreferenceListBuilder { + private final Map queryParams = new LinkedHashMap<>(); + + private PreferenceListBuilder() {} + + public SettingGroupFilter settingGroup() { + return new SettingGroupFilter("setting_group", this, queryParams); + } + + public PreferenceListParams build() { + return new PreferenceListParams(this); + } + + public static final class SettingGroupFilter + extends EnumFilter { + SettingGroupFilter( + String fieldName, PreferenceListBuilder builder, Map params) { + super(fieldName, builder, params, SettingGroup::getValue); + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().is(SettingGroup.YOUR_VALUE)}
+ * + * @see #is(SettingGroup) + */ + @Deprecated + public PreferenceListBuilder is(String value) { + params.put(fieldName + "[is]", value); + return builder; + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().isNot(SettingGroup.YOUR_VALUE)}
+ * + * @see #isNot(SettingGroup) + */ + @Deprecated + public PreferenceListBuilder isNot(String value) { + params.put(fieldName + "[is_not]", value); + return builder; + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().in(SettingGroup.VALUE1, SettingGroup.VALUE2)}
+ * + * @see #in(SettingGroup[]) + */ + @Deprecated + public PreferenceListBuilder in(String... values) { + params.put(fieldName + "[in]", "[" + String.join(",", values) + "]"); + return builder; + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().notIn(SettingGroup.VALUE1, SettingGroup.VALUE2)}
+ * + * @see #notIn(SettingGroup[]) + */ + @Deprecated + public PreferenceListBuilder notIn(String... values) { + params.put(fieldName + "[not_in]", "[" + String.join(",", values) + "]"); + return builder; + } + } + } + + public enum SettingGroupIs { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroupIs was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroupIs(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroupIs fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroupIs enumValue : SettingGroupIs.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum SettingGroupIn { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroupIn was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroupIn(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroupIn fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroupIn enumValue : SettingGroupIn.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum SettingGroup { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroup was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroup(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroup fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroup enumValue : SettingGroup.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } +} diff --git a/src/main/java/com/chargebee/v4/models/preference/params/PreferenceUpsertParams.java b/src/main/java/com/chargebee/v4/models/preference/params/PreferenceUpsertParams.java new file mode 100644 index 00000000..e6378291 --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preference/params/PreferenceUpsertParams.java @@ -0,0 +1,200 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ +package com.chargebee.v4.models.preference.params; + +import com.chargebee.v4.internal.Recommended; +import com.chargebee.v4.internal.JsonUtil; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.List; + +public final class PreferenceUpsertParams { + + private final List preferences; + + private PreferenceUpsertParams(PreferenceUpsertBuilder builder) { + + this.preferences = builder.preferences; + } + + public List getPreferences() { + return preferences; + } + + /** Get the form data for this request. */ + public Map toFormData() { + Map formData = new LinkedHashMap<>(); + + if (this.preferences != null) { + + // List of objects + for (int i = 0; i < this.preferences.size(); i++) { + PreferencesParams item = this.preferences.get(i); + if (item != null) { + Map itemData = item.toFormData(); + for (Map.Entry entry : itemData.entrySet()) { + String indexedKey = "preferences[" + entry.getKey() + "][" + i + "]"; + formData.put(indexedKey, entry.getValue()); + } + } + } + } + + return formData; + } + + /** Create a new builder for PreferenceUpsertParams. */ + @Recommended(reason = "Preferred for reusability, validation, and LLM-friendliness") + public static PreferenceUpsertBuilder builder() { + return new PreferenceUpsertBuilder(); + } + + public static final class PreferenceUpsertBuilder { + + private List preferences; + + private PreferenceUpsertBuilder() {} + + public PreferenceUpsertBuilder preferences(List value) { + this.preferences = value; + return this; + } + + public PreferenceUpsertParams build() { + return new PreferenceUpsertParams(this); + } + } + + public static final class PreferencesParams { + + private final String id; + + private final String value; + + private final Boolean allowOverrideInInterface; + + private final Boolean allowOverrideInApi; + + private final List variants; + + private PreferencesParams(PreferencesBuilder builder) { + + this.id = builder.id; + + this.value = builder.value; + + this.allowOverrideInInterface = builder.allowOverrideInInterface; + + this.allowOverrideInApi = builder.allowOverrideInApi; + + this.variants = builder.variants; + } + + public String getId() { + return id; + } + + public String getValue() { + return value; + } + + public Boolean getAllowOverrideInInterface() { + return allowOverrideInInterface; + } + + public Boolean getAllowOverrideInApi() { + return allowOverrideInApi; + } + + public List getVariants() { + return variants; + } + + /** Get the form data for this request. */ + public Map toFormData() { + Map formData = new LinkedHashMap<>(); + + if (this.id != null) { + + formData.put("id", this.id); + } + + if (this.value != null) { + + formData.put("value", this.value); + } + + if (this.allowOverrideInInterface != null) { + + formData.put("allow_override_in_interface", this.allowOverrideInInterface); + } + + if (this.allowOverrideInApi != null) { + + formData.put("allow_override_in_api", this.allowOverrideInApi); + } + + if (this.variants != null) { + + formData.put("variants", JsonUtil.toJson(this.variants)); + } + + return formData; + } + + /** Create a new builder for PreferencesParams. */ + @Recommended(reason = "Preferred for reusability, validation, and LLM-friendliness") + public static PreferencesBuilder builder() { + return new PreferencesBuilder(); + } + + public static final class PreferencesBuilder { + + private String id; + + private String value; + + private Boolean allowOverrideInInterface; + + private Boolean allowOverrideInApi; + + private List variants; + + private PreferencesBuilder() {} + + public PreferencesBuilder id(String value) { + this.id = value; + return this; + } + + public PreferencesBuilder value(String value) { + this.value = value; + return this; + } + + public PreferencesBuilder allowOverrideInInterface(Boolean value) { + this.allowOverrideInInterface = value; + return this; + } + + public PreferencesBuilder allowOverrideInApi(Boolean value) { + this.allowOverrideInApi = value; + return this; + } + + public PreferencesBuilder variants(List value) { + this.variants = value; + return this; + } + + public PreferencesParams build() { + return new PreferencesParams(this); + } + } + } +} diff --git a/src/main/java/com/chargebee/v4/models/preference/responses/PreferenceListResponse.java b/src/main/java/com/chargebee/v4/models/preference/responses/PreferenceListResponse.java new file mode 100644 index 00000000..d4a98b93 --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preference/responses/PreferenceListResponse.java @@ -0,0 +1,99 @@ +package com.chargebee.v4.models.preference.responses; + +import com.chargebee.v4.models.preference.Preference; + +import com.chargebee.v4.models.BaseResponse; +import com.chargebee.v4.internal.JsonUtil; +import com.google.gson.JsonObject; +import com.chargebee.v4.transport.Response; + +/** + * Immutable response object for PreferenceList operation. Contains the response data from a single + * resource get operation. + */ +public final class PreferenceListResponse extends BaseResponse { + private final Preference preference; + + private PreferenceListResponse(Builder builder) { + super(builder.httpResponse); + + this.preference = builder.preference; + } + + /** Parse JSON response into PreferenceListResponse object. */ + public static PreferenceListResponse fromJson(String json) { + return fromJson(json, null); + } + + /** Parse JSON response into PreferenceListResponse object with HTTP response. */ + public static PreferenceListResponse fromJson(String json, Response httpResponse) { + try { + JsonObject jsonObj = JsonUtil.parse(json); + Builder builder = builder(); + + JsonObject __preferenceObj = JsonUtil.getJsonObject(jsonObj, "preference"); + if (__preferenceObj != null) { + builder.preference(Preference.fromJson(__preferenceObj)); + } + + builder.httpResponse(httpResponse); + return builder.build(); + } catch (Exception e) { + throw new RuntimeException("Failed to parse PreferenceListResponse from JSON", e); + } + } + + /** Create a new builder for PreferenceListResponse. */ + public static Builder builder() { + return new Builder(); + } + + /** Builder for PreferenceListResponse. */ + public static class Builder { + + private Preference preference; + + private Response httpResponse; + + private Builder() {} + + public Builder preference(Preference preference) { + this.preference = preference; + return this; + } + + public Builder httpResponse(Response httpResponse) { + this.httpResponse = httpResponse; + return this; + } + + public PreferenceListResponse build() { + return new PreferenceListResponse(this); + } + } + + /** Get the preference from the response. */ + public Preference getPreference() { + return preference; + } + + @Override + public String toString() { + return "PreferenceListResponse{" + "preference=" + preference + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PreferenceListResponse that = (PreferenceListResponse) o; + return java.util.Objects.equals(preference, that.preference); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(preference); + } +} diff --git a/src/main/java/com/chargebee/v4/models/preference/responses/PreferenceUpsertResponse.java b/src/main/java/com/chargebee/v4/models/preference/responses/PreferenceUpsertResponse.java new file mode 100644 index 00000000..4129e22b --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preference/responses/PreferenceUpsertResponse.java @@ -0,0 +1,99 @@ +package com.chargebee.v4.models.preference.responses; + +import com.chargebee.v4.models.preference.Preference; + +import com.chargebee.v4.models.BaseResponse; +import com.chargebee.v4.internal.JsonUtil; +import com.google.gson.JsonObject; +import com.chargebee.v4.transport.Response; + +/** + * Immutable response object for PreferenceUpsert operation. Contains the response data from the + * API. + */ +public final class PreferenceUpsertResponse extends BaseResponse { + private final Preference preference; + + private PreferenceUpsertResponse(Builder builder) { + super(builder.httpResponse); + + this.preference = builder.preference; + } + + /** Parse JSON response into PreferenceUpsertResponse object. */ + public static PreferenceUpsertResponse fromJson(String json) { + return fromJson(json, null); + } + + /** Parse JSON response into PreferenceUpsertResponse object with HTTP response. */ + public static PreferenceUpsertResponse fromJson(String json, Response httpResponse) { + try { + JsonObject jsonObj = JsonUtil.parse(json); + Builder builder = builder(); + + JsonObject __preferenceObj = JsonUtil.getJsonObject(jsonObj, "preference"); + if (__preferenceObj != null) { + builder.preference(Preference.fromJson(__preferenceObj)); + } + + builder.httpResponse(httpResponse); + return builder.build(); + } catch (Exception e) { + throw new RuntimeException("Failed to parse PreferenceUpsertResponse from JSON", e); + } + } + + /** Create a new builder for PreferenceUpsertResponse. */ + public static Builder builder() { + return new Builder(); + } + + /** Builder for PreferenceUpsertResponse. */ + public static class Builder { + + private Preference preference; + + private Response httpResponse; + + private Builder() {} + + public Builder preference(Preference preference) { + this.preference = preference; + return this; + } + + public Builder httpResponse(Response httpResponse) { + this.httpResponse = httpResponse; + return this; + } + + public PreferenceUpsertResponse build() { + return new PreferenceUpsertResponse(this); + } + } + + /** Get the preference from the response. */ + public Preference getPreference() { + return preference; + } + + @Override + public String toString() { + return "PreferenceUpsertResponse{" + "preference=" + preference + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PreferenceUpsertResponse that = (PreferenceUpsertResponse) o; + return java.util.Objects.equals(preference, that.preference); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(preference); + } +} diff --git a/src/main/java/com/chargebee/v4/models/preferenceDefinition/PreferenceDefinition.java b/src/main/java/com/chargebee/v4/models/preferenceDefinition/PreferenceDefinition.java new file mode 100644 index 00000000..751147e4 --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preferenceDefinition/PreferenceDefinition.java @@ -0,0 +1,1185 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ + +package com.chargebee.v4.models.preferenceDefinition; + +import com.chargebee.v4.internal.JsonUtil; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.util.List; + +public class PreferenceDefinition { + + private String id; + private SettingGroup settingGroup; + private String mainGroup; + private String subGroup; + private String description; + @Deprecated private String docLink; + private AccessMode accessMode; + private Boolean overridableInInterface; + private Boolean overridableInApi; + private ApplicabilityOperator applicabilityOperator; + @Deprecated private Boolean isNamespace; + @Deprecated private String keyInternalName; + private List applicability; + private ValueSchema valueSchema; + private List variantCriteria; + + public String getId() { + return id; + } + + public SettingGroup getSettingGroup() { + return settingGroup; + } + + public String getMainGroup() { + return mainGroup; + } + + public String getSubGroup() { + return subGroup; + } + + public String getDescription() { + return description; + } + + @Deprecated + public String getDocLink() { + return docLink; + } + + public AccessMode getAccessMode() { + return accessMode; + } + + public Boolean getOverridableInInterface() { + return overridableInInterface; + } + + public Boolean getOverridableInApi() { + return overridableInApi; + } + + public ApplicabilityOperator getApplicabilityOperator() { + return applicabilityOperator; + } + + @Deprecated + public Boolean getIsNamespace() { + return isNamespace; + } + + @Deprecated + public String getKeyInternalName() { + return keyInternalName; + } + + public List getApplicability() { + return applicability; + } + + public ValueSchema getValueSchema() { + return valueSchema; + } + + public List getVariantCriteria() { + return variantCriteria; + } + + public enum SettingGroup { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroup was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroup(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroup fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroup enumValue : SettingGroup.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum AccessMode { + READ_WRITE("read_write"), + + READ_ONLY("read_only"), + + /** An enum member indicating that AccessMode was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + AccessMode(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static AccessMode fromString(String value) { + if (value == null) return _UNKNOWN; + for (AccessMode enumValue : AccessMode.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum ApplicabilityOperator { + AND("and"), + + OR("or"), + + /** + * An enum member indicating that ApplicabilityOperator was instantiated with an unknown value. + */ + _UNKNOWN(null); + private final String value; + + ApplicabilityOperator(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static ApplicabilityOperator fromString(String value) { + if (value == null) return _UNKNOWN; + for (ApplicabilityOperator enumValue : ApplicabilityOperator.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static PreferenceDefinition fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static PreferenceDefinition fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static PreferenceDefinition fromJson(JsonObject jsonObj) { + PreferenceDefinition obj = new PreferenceDefinition(); + + obj.id = JsonUtil.getString(jsonObj, "id"); + + obj.settingGroup = SettingGroup.fromString(JsonUtil.getString(jsonObj, "setting_group")); + + obj.mainGroup = JsonUtil.getString(jsonObj, "main_group"); + + obj.subGroup = JsonUtil.getString(jsonObj, "sub_group"); + + obj.description = JsonUtil.getString(jsonObj, "description"); + + obj.docLink = JsonUtil.getString(jsonObj, "doc_link"); + + obj.accessMode = AccessMode.fromString(JsonUtil.getString(jsonObj, "access_mode")); + + obj.overridableInInterface = JsonUtil.getBoolean(jsonObj, "overridable_in_interface"); + + obj.overridableInApi = JsonUtil.getBoolean(jsonObj, "overridable_in_api"); + + obj.applicabilityOperator = + ApplicabilityOperator.fromString(JsonUtil.getString(jsonObj, "applicability_operator")); + + obj.isNamespace = JsonUtil.getBoolean(jsonObj, "is_namespace"); + + obj.keyInternalName = JsonUtil.getString(jsonObj, "key_internal_name"); + + obj.applicability = + JsonUtil.mapArray(JsonUtil.getJsonArray(jsonObj, "applicability"), Applicability::fromJson); + + JsonObject __valueSchemaObj = JsonUtil.getJsonObject(jsonObj, "value_schema"); + if (__valueSchemaObj != null) { + obj.valueSchema = ValueSchema.fromJson(__valueSchemaObj); + } + + obj.variantCriteria = + JsonUtil.mapArray( + JsonUtil.getJsonArray(jsonObj, "variant_criteria"), VariantCriteria::fromJson); + + return obj; + } + + @Override + public String toString() { + return "PreferenceDefinition{" + + "id=" + + id + + ", settingGroup=" + + settingGroup + + ", mainGroup=" + + mainGroup + + ", subGroup=" + + subGroup + + ", description=" + + description + + ", docLink=" + + docLink + + ", accessMode=" + + accessMode + + ", overridableInInterface=" + + overridableInInterface + + ", overridableInApi=" + + overridableInApi + + ", applicabilityOperator=" + + applicabilityOperator + + ", isNamespace=" + + isNamespace + + ", keyInternalName=" + + keyInternalName + + ", applicability=" + + applicability + + ", valueSchema=" + + valueSchema + + ", variantCriteria=" + + variantCriteria + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PreferenceDefinition that = (PreferenceDefinition) o; + return java.util.Objects.equals(id, that.id) + && java.util.Objects.equals(settingGroup, that.settingGroup) + && java.util.Objects.equals(mainGroup, that.mainGroup) + && java.util.Objects.equals(subGroup, that.subGroup) + && java.util.Objects.equals(description, that.description) + && java.util.Objects.equals(docLink, that.docLink) + && java.util.Objects.equals(accessMode, that.accessMode) + && java.util.Objects.equals(overridableInInterface, that.overridableInInterface) + && java.util.Objects.equals(overridableInApi, that.overridableInApi) + && java.util.Objects.equals(applicabilityOperator, that.applicabilityOperator) + && java.util.Objects.equals(isNamespace, that.isNamespace) + && java.util.Objects.equals(keyInternalName, that.keyInternalName) + && java.util.Objects.equals(applicability, that.applicability) + && java.util.Objects.equals(valueSchema, that.valueSchema) + && java.util.Objects.equals(variantCriteria, that.variantCriteria); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash( + id, + settingGroup, + mainGroup, + subGroup, + description, + docLink, + accessMode, + overridableInInterface, + overridableInApi, + applicabilityOperator, + isNamespace, + keyInternalName, + applicability, + valueSchema, + variantCriteria); + } + + public static class Applicability { + + private String setting; + private Operator operator; + private List values; + + public String getSetting() { + return setting; + } + + public Operator getOperator() { + return operator; + } + + public List getValues() { + return values; + } + + public enum Operator { + IS("is"), + + IN("in"), + + /** An enum member indicating that Operator was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Operator(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Operator fromString(String value) { + if (value == null) return _UNKNOWN; + for (Operator enumValue : Operator.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static Applicability fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static Applicability fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static Applicability fromJson(JsonObject jsonObj) { + Applicability obj = new Applicability(); + + obj.setting = JsonUtil.getString(jsonObj, "setting"); + + obj.operator = Operator.fromString(JsonUtil.getString(jsonObj, "operator")); + + JsonArray __valuesArr = JsonUtil.getJsonArray(jsonObj, "values"); + if (__valuesArr != null) { + obj.values = JsonUtil.parseArrayOfString(__valuesArr); + } + + return obj; + } + + @Override + public String toString() { + return "Applicability{" + + "setting=" + + setting + + ", operator=" + + operator + + ", values=" + + values + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Applicability that = (Applicability) o; + return java.util.Objects.equals(setting, that.setting) + && java.util.Objects.equals(operator, that.operator) + && java.util.Objects.equals(values, that.values); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(setting, operator, values); + } + } + + public static class ValueSchema { + + private Type type; + private Integer minValue; + private Integer maxValue; + private Integer maxChars; + private List allowedValues; + private Items items; + + public Type getType() { + return type; + } + + public Integer getMinValue() { + return minValue; + } + + public Integer getMaxValue() { + return maxValue; + } + + public Integer getMaxChars() { + return maxChars; + } + + public List getAllowedValues() { + return allowedValues; + } + + public Items getItems() { + return items; + } + + public enum Type { + BOOLEAN("boolean"), + + STRING("string"), + + NUMERIC("numeric"), + + TIMESTAMP("timestamp"), + + DATE("date"), + + LIST("list"), + + /** An enum member indicating that Type was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Type(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Type fromString(String value) { + if (value == null) return _UNKNOWN; + for (Type enumValue : Type.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static ValueSchema fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static ValueSchema fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static ValueSchema fromJson(JsonObject jsonObj) { + ValueSchema obj = new ValueSchema(); + + obj.type = Type.fromString(JsonUtil.getString(jsonObj, "type")); + + obj.minValue = JsonUtil.getInteger(jsonObj, "min_value"); + + obj.maxValue = JsonUtil.getInteger(jsonObj, "max_value"); + + obj.maxChars = JsonUtil.getInteger(jsonObj, "max_chars"); + + obj.allowedValues = + JsonUtil.mapArray( + JsonUtil.getJsonArray(jsonObj, "allowed_values"), AllowedValues::fromJson); + + JsonObject __itemsObj = JsonUtil.getJsonObject(jsonObj, "items"); + if (__itemsObj != null) { + obj.items = Items.fromJson(__itemsObj); + } + + return obj; + } + + @Override + public String toString() { + return "ValueSchema{" + + "type=" + + type + + ", minValue=" + + minValue + + ", maxValue=" + + maxValue + + ", maxChars=" + + maxChars + + ", allowedValues=" + + allowedValues + + ", items=" + + items + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ValueSchema that = (ValueSchema) o; + return java.util.Objects.equals(type, that.type) + && java.util.Objects.equals(minValue, that.minValue) + && java.util.Objects.equals(maxValue, that.maxValue) + && java.util.Objects.equals(maxChars, that.maxChars) + && java.util.Objects.equals(allowedValues, that.allowedValues) + && java.util.Objects.equals(items, that.items); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(type, minValue, maxValue, maxChars, allowedValues, items); + } + + public static class AllowedValues { + + private String value; + private String description; + + public String getValue() { + return value; + } + + public String getDescription() { + return description; + } + + public static AllowedValues fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static AllowedValues fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static AllowedValues fromJson(JsonObject jsonObj) { + AllowedValues obj = new AllowedValues(); + + obj.value = JsonUtil.getString(jsonObj, "value"); + + obj.description = JsonUtil.getString(jsonObj, "description"); + + return obj; + } + + @Override + public String toString() { + return "AllowedValues{" + "value=" + value + ", description=" + description + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllowedValues that = (AllowedValues) o; + return java.util.Objects.equals(value, that.value) + && java.util.Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(value, description); + } + } + + public static class Items { + + private Type type; + private List allowedValues; + + public Type getType() { + return type; + } + + public List getAllowedValues() { + return allowedValues; + } + + public enum Type { + BOOLEAN("boolean"), + + STRING("string"), + + NUMERIC("numeric"), + + TIMESTAMP("timestamp"), + + DATE("date"), + + LIST("list"), + + /** An enum member indicating that Type was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Type(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Type fromString(String value) { + if (value == null) return _UNKNOWN; + for (Type enumValue : Type.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static Items fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static Items fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static Items fromJson(JsonObject jsonObj) { + Items obj = new Items(); + + obj.type = Type.fromString(JsonUtil.getString(jsonObj, "type")); + + obj.allowedValues = + JsonUtil.mapArray( + JsonUtil.getJsonArray(jsonObj, "allowed_values"), AllowedValues::fromJson); + + return obj; + } + + @Override + public String toString() { + return "Items{" + "type=" + type + ", allowedValues=" + allowedValues + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Items that = (Items) o; + return java.util.Objects.equals(type, that.type) + && java.util.Objects.equals(allowedValues, that.allowedValues); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(type, allowedValues); + } + + public static class AllowedValues { + + private String value; + private String description; + + public String getValue() { + return value; + } + + public String getDescription() { + return description; + } + + public static AllowedValues fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static AllowedValues fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static AllowedValues fromJson(JsonObject jsonObj) { + AllowedValues obj = new AllowedValues(); + + obj.value = JsonUtil.getString(jsonObj, "value"); + + obj.description = JsonUtil.getString(jsonObj, "description"); + + return obj; + } + + @Override + public String toString() { + return "AllowedValues{" + "value=" + value + ", description=" + description + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllowedValues that = (AllowedValues) o; + return java.util.Objects.equals(value, that.value) + && java.util.Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(value, description); + } + } + } + } + + public static class VariantCriteria { + + private Operand operand; + private List allowedOperator; + private ValueSchema valueSchema; + + public Operand getOperand() { + return operand; + } + + public List getAllowedOperator() { + return allowedOperator; + } + + public ValueSchema getValueSchema() { + return valueSchema; + } + + public enum Operand { + REQUEST_SOURCE("request_source"), + + /** An enum member indicating that Operand was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Operand(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Operand fromString(String value) { + if (value == null) return _UNKNOWN; + for (Operand enumValue : Operand.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static VariantCriteria fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static VariantCriteria fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static VariantCriteria fromJson(JsonObject jsonObj) { + VariantCriteria obj = new VariantCriteria(); + + obj.operand = Operand.fromString(JsonUtil.getString(jsonObj, "operand")); + + JsonArray __allowedOperatorArr = JsonUtil.getJsonArray(jsonObj, "allowed_operator"); + if (__allowedOperatorArr != null) { + obj.allowedOperator = JsonUtil.parseArrayOfString(__allowedOperatorArr); + } + + JsonObject __valueSchemaObj = JsonUtil.getJsonObject(jsonObj, "value_schema"); + if (__valueSchemaObj != null) { + obj.valueSchema = ValueSchema.fromJson(__valueSchemaObj); + } + + return obj; + } + + @Override + public String toString() { + return "VariantCriteria{" + + "operand=" + + operand + + ", allowedOperator=" + + allowedOperator + + ", valueSchema=" + + valueSchema + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VariantCriteria that = (VariantCriteria) o; + return java.util.Objects.equals(operand, that.operand) + && java.util.Objects.equals(allowedOperator, that.allowedOperator) + && java.util.Objects.equals(valueSchema, that.valueSchema); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(operand, allowedOperator, valueSchema); + } + + public static class ValueSchema { + + private Type type; + private Integer minValue; + private Integer maxValue; + private Integer maxChars; + private List allowedValues; + private Items items; + + public Type getType() { + return type; + } + + public Integer getMinValue() { + return minValue; + } + + public Integer getMaxValue() { + return maxValue; + } + + public Integer getMaxChars() { + return maxChars; + } + + public List getAllowedValues() { + return allowedValues; + } + + public Items getItems() { + return items; + } + + public enum Type { + BOOLEAN("boolean"), + + STRING("string"), + + NUMERIC("numeric"), + + TIMESTAMP("timestamp"), + + DATE("date"), + + LIST("list"), + + /** An enum member indicating that Type was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Type(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Type fromString(String value) { + if (value == null) return _UNKNOWN; + for (Type enumValue : Type.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static ValueSchema fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static ValueSchema fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static ValueSchema fromJson(JsonObject jsonObj) { + ValueSchema obj = new ValueSchema(); + + obj.type = Type.fromString(JsonUtil.getString(jsonObj, "type")); + + obj.minValue = JsonUtil.getInteger(jsonObj, "min_value"); + + obj.maxValue = JsonUtil.getInteger(jsonObj, "max_value"); + + obj.maxChars = JsonUtil.getInteger(jsonObj, "max_chars"); + + obj.allowedValues = + JsonUtil.mapArray( + JsonUtil.getJsonArray(jsonObj, "allowed_values"), AllowedValues::fromJson); + + JsonObject __itemsObj = JsonUtil.getJsonObject(jsonObj, "items"); + if (__itemsObj != null) { + obj.items = Items.fromJson(__itemsObj); + } + + return obj; + } + + @Override + public String toString() { + return "ValueSchema{" + + "type=" + + type + + ", minValue=" + + minValue + + ", maxValue=" + + maxValue + + ", maxChars=" + + maxChars + + ", allowedValues=" + + allowedValues + + ", items=" + + items + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ValueSchema that = (ValueSchema) o; + return java.util.Objects.equals(type, that.type) + && java.util.Objects.equals(minValue, that.minValue) + && java.util.Objects.equals(maxValue, that.maxValue) + && java.util.Objects.equals(maxChars, that.maxChars) + && java.util.Objects.equals(allowedValues, that.allowedValues) + && java.util.Objects.equals(items, that.items); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(type, minValue, maxValue, maxChars, allowedValues, items); + } + + public static class AllowedValues { + + private String value; + private String description; + + public String getValue() { + return value; + } + + public String getDescription() { + return description; + } + + public static AllowedValues fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static AllowedValues fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static AllowedValues fromJson(JsonObject jsonObj) { + AllowedValues obj = new AllowedValues(); + + obj.value = JsonUtil.getString(jsonObj, "value"); + + obj.description = JsonUtil.getString(jsonObj, "description"); + + return obj; + } + + @Override + public String toString() { + return "AllowedValues{" + "value=" + value + ", description=" + description + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllowedValues that = (AllowedValues) o; + return java.util.Objects.equals(value, that.value) + && java.util.Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(value, description); + } + } + + public static class Items { + + private Type type; + private List allowedValues; + + public Type getType() { + return type; + } + + public List getAllowedValues() { + return allowedValues; + } + + public enum Type { + BOOLEAN("boolean"), + + STRING("string"), + + NUMERIC("numeric"), + + TIMESTAMP("timestamp"), + + DATE("date"), + + LIST("list"), + + /** An enum member indicating that Type was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + Type(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Type fromString(String value) { + if (value == null) return _UNKNOWN; + for (Type enumValue : Type.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public static Items fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static Items fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static Items fromJson(JsonObject jsonObj) { + Items obj = new Items(); + + obj.type = Type.fromString(JsonUtil.getString(jsonObj, "type")); + + obj.allowedValues = + JsonUtil.mapArray( + JsonUtil.getJsonArray(jsonObj, "allowed_values"), AllowedValues::fromJson); + + return obj; + } + + @Override + public String toString() { + return "Items{" + "type=" + type + ", allowedValues=" + allowedValues + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Items that = (Items) o; + return java.util.Objects.equals(type, that.type) + && java.util.Objects.equals(allowedValues, that.allowedValues); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(type, allowedValues); + } + + public static class AllowedValues { + + private String value; + private String description; + + public String getValue() { + return value; + } + + public String getDescription() { + return description; + } + + public static AllowedValues fromJson(String json) { + return fromJson(JsonUtil.parse(json)); + } + + public static AllowedValues fromJson(java.util.Map map) { + return fromJson(JsonUtil.toJson(map)); + } + + public static AllowedValues fromJson(JsonObject jsonObj) { + AllowedValues obj = new AllowedValues(); + + obj.value = JsonUtil.getString(jsonObj, "value"); + + obj.description = JsonUtil.getString(jsonObj, "description"); + + return obj; + } + + @Override + public String toString() { + return "AllowedValues{" + "value=" + value + ", description=" + description + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + AllowedValues that = (AllowedValues) o; + return java.util.Objects.equals(value, that.value) + && java.util.Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(value, description); + } + } + } + } + } +} diff --git a/src/main/java/com/chargebee/v4/models/preferenceDefinition/params/PreferenceDefinitionListDefinitionsParams.java b/src/main/java/com/chargebee/v4/models/preferenceDefinition/params/PreferenceDefinitionListDefinitionsParams.java new file mode 100644 index 00000000..0e6a3376 --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preferenceDefinition/params/PreferenceDefinitionListDefinitionsParams.java @@ -0,0 +1,209 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ + +package com.chargebee.v4.models.preferenceDefinition.params; + +import com.chargebee.v4.internal.Recommended; +import com.chargebee.v4.filters.EnumFilter; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +public final class PreferenceDefinitionListDefinitionsParams { + + private final Map queryParams; + + private PreferenceDefinitionListDefinitionsParams( + PreferenceDefinitionListDefinitionsBuilder builder) { + this.queryParams = Collections.unmodifiableMap(new LinkedHashMap<>(builder.queryParams)); + } + + /** Get the query parameters for this request. */ + public Map toQueryParams() { + return queryParams; + } + + public PreferenceDefinitionListDefinitionsBuilder toBuilder() { + PreferenceDefinitionListDefinitionsBuilder builder = + new PreferenceDefinitionListDefinitionsBuilder(); + builder.queryParams.putAll(queryParams); + return builder; + } + + /** Create a new builder for PreferenceDefinitionListDefinitionsParams. */ + @Recommended(reason = "Preferred for reusability, validation, and LLM-friendliness") + public static PreferenceDefinitionListDefinitionsBuilder builder() { + return new PreferenceDefinitionListDefinitionsBuilder(); + } + + public static final class PreferenceDefinitionListDefinitionsBuilder { + private final Map queryParams = new LinkedHashMap<>(); + + private PreferenceDefinitionListDefinitionsBuilder() {} + + public SettingGroupFilter settingGroup() { + return new SettingGroupFilter("setting_group", this, queryParams); + } + + public PreferenceDefinitionListDefinitionsParams build() { + return new PreferenceDefinitionListDefinitionsParams(this); + } + + public static final class SettingGroupFilter + extends EnumFilter { + SettingGroupFilter( + String fieldName, + PreferenceDefinitionListDefinitionsBuilder builder, + Map params) { + super(fieldName, builder, params, SettingGroup::getValue); + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().is(SettingGroup.YOUR_VALUE)}
+ * + * @see #is(SettingGroup) + */ + @Deprecated + public PreferenceDefinitionListDefinitionsBuilder is(String value) { + params.put(fieldName + "[is]", value); + return builder; + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().isNot(SettingGroup.YOUR_VALUE)}
+ * + * @see #isNot(SettingGroup) + */ + @Deprecated + public PreferenceDefinitionListDefinitionsBuilder isNot(String value) { + params.put(fieldName + "[is_not]", value); + return builder; + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().in(SettingGroup.VALUE1, SettingGroup.VALUE2)}
+ * + * @see #in(SettingGroup[]) + */ + @Deprecated + public PreferenceDefinitionListDefinitionsBuilder in(String... values) { + params.put(fieldName + "[in]", "[" + String.join(",", values) + "]"); + return builder; + } + + /** + * @deprecated This method accepting raw String will be removed in a future version. Use the + * type-safe enum overload instead: + *
{@code .settingGroup().notIn(SettingGroup.VALUE1, SettingGroup.VALUE2)}
+ * + * @see #notIn(SettingGroup[]) + */ + @Deprecated + public PreferenceDefinitionListDefinitionsBuilder notIn(String... values) { + params.put(fieldName + "[not_in]", "[" + String.join(",", values) + "]"); + return builder; + } + } + } + + public enum SettingGroupIs { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroupIs was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroupIs(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroupIs fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroupIs enumValue : SettingGroupIs.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum SettingGroupIn { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroupIn was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroupIn(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroupIn fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroupIn enumValue : SettingGroupIn.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } + + public enum SettingGroup { + CONTRACT_TERMS("contract_terms"), + + SUB_CANCELATION("sub_cancelation"), + + BILLING_RULES("billing_rules"), + + /** An enum member indicating that SettingGroup was instantiated with an unknown value. */ + _UNKNOWN(null); + private final String value; + + SettingGroup(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static SettingGroup fromString(String value) { + if (value == null) return _UNKNOWN; + for (SettingGroup enumValue : SettingGroup.values()) { + if (enumValue.value != null && enumValue.value.equals(value)) { + return enumValue; + } + } + return _UNKNOWN; + } + } +} diff --git a/src/main/java/com/chargebee/v4/models/preferenceDefinition/responses/PreferenceDefinitionListDefinitionsResponse.java b/src/main/java/com/chargebee/v4/models/preferenceDefinition/responses/PreferenceDefinitionListDefinitionsResponse.java new file mode 100644 index 00000000..f0e8d702 --- /dev/null +++ b/src/main/java/com/chargebee/v4/models/preferenceDefinition/responses/PreferenceDefinitionListDefinitionsResponse.java @@ -0,0 +1,108 @@ +package com.chargebee.v4.models.preferenceDefinition.responses; + +import com.chargebee.v4.models.preferenceDefinition.PreferenceDefinition; + +import com.chargebee.v4.models.BaseResponse; +import com.chargebee.v4.internal.JsonUtil; +import com.google.gson.JsonObject; +import com.chargebee.v4.transport.Response; + +/** + * Immutable response object for PreferenceDefinitionListDefinitions operation. Contains the + * response data from a single resource get operation. + */ +public final class PreferenceDefinitionListDefinitionsResponse extends BaseResponse { + private final PreferenceDefinition preferenceDefinition; + + private PreferenceDefinitionListDefinitionsResponse(Builder builder) { + super(builder.httpResponse); + + this.preferenceDefinition = builder.preferenceDefinition; + } + + /** Parse JSON response into PreferenceDefinitionListDefinitionsResponse object. */ + public static PreferenceDefinitionListDefinitionsResponse fromJson(String json) { + return fromJson(json, null); + } + + /** + * Parse JSON response into PreferenceDefinitionListDefinitionsResponse object with HTTP response. + */ + public static PreferenceDefinitionListDefinitionsResponse fromJson( + String json, Response httpResponse) { + try { + JsonObject jsonObj = JsonUtil.parse(json); + Builder builder = builder(); + + JsonObject __preferenceDefinitionObj = + JsonUtil.getJsonObject(jsonObj, "preference_definition"); + if (__preferenceDefinitionObj != null) { + builder.preferenceDefinition(PreferenceDefinition.fromJson(__preferenceDefinitionObj)); + } + + builder.httpResponse(httpResponse); + return builder.build(); + } catch (Exception e) { + throw new RuntimeException( + "Failed to parse PreferenceDefinitionListDefinitionsResponse from JSON", e); + } + } + + /** Create a new builder for PreferenceDefinitionListDefinitionsResponse. */ + public static Builder builder() { + return new Builder(); + } + + /** Builder for PreferenceDefinitionListDefinitionsResponse. */ + public static class Builder { + + private PreferenceDefinition preferenceDefinition; + + private Response httpResponse; + + private Builder() {} + + public Builder preferenceDefinition(PreferenceDefinition preferenceDefinition) { + this.preferenceDefinition = preferenceDefinition; + return this; + } + + public Builder httpResponse(Response httpResponse) { + this.httpResponse = httpResponse; + return this; + } + + public PreferenceDefinitionListDefinitionsResponse build() { + return new PreferenceDefinitionListDefinitionsResponse(this); + } + } + + /** Get the preferenceDefinition from the response. */ + public PreferenceDefinition getPreferenceDefinition() { + return preferenceDefinition; + } + + @Override + public String toString() { + return "PreferenceDefinitionListDefinitionsResponse{" + + "preferenceDefinition=" + + preferenceDefinition + + "}"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PreferenceDefinitionListDefinitionsResponse that = + (PreferenceDefinitionListDefinitionsResponse) o; + return java.util.Objects.equals(preferenceDefinition, that.preferenceDefinition); + } + + @Override + public int hashCode() { + + return java.util.Objects.hash(preferenceDefinition); + } +} diff --git a/src/main/java/com/chargebee/v4/services/PreferenceDefinitionService.java b/src/main/java/com/chargebee/v4/services/PreferenceDefinitionService.java new file mode 100644 index 00000000..e7bcc594 --- /dev/null +++ b/src/main/java/com/chargebee/v4/services/PreferenceDefinitionService.java @@ -0,0 +1,100 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ + +package com.chargebee.v4.services; + +import com.chargebee.v4.client.ChargebeeClient; +import com.chargebee.v4.client.request.RequestOptions; +import com.chargebee.v4.exceptions.ChargebeeException; +import com.chargebee.v4.transport.Response; +import java.util.concurrent.CompletableFuture; + +import com.chargebee.v4.models.preferenceDefinition.params.PreferenceDefinitionListDefinitionsParams; + +import com.chargebee.v4.models.preferenceDefinition.responses.PreferenceDefinitionListDefinitionsResponse; + +public final class PreferenceDefinitionService extends BaseService { + + private final ServiceConfig config; + + public PreferenceDefinitionService(ChargebeeClient client) { + super(client); + this.config = ServiceConfig.defaultConfig(); + } + + private PreferenceDefinitionService(ChargebeeClient client, RequestOptions options) { + super(client, options); + this.config = ServiceConfig.defaultConfig(); + } + + private PreferenceDefinitionService( + ChargebeeClient client, RequestOptions options, ServiceConfig config) { + super(client, options); + this.config = config; + } + + @Override + PreferenceDefinitionService with(RequestOptions newOptions) { + return new PreferenceDefinitionService(client, newOptions, config); + } + + /** + * Apply per-request options for this service instance. Users can chain .withOptions or .options + * to set headers and other options. + */ + public PreferenceDefinitionService withOptions(RequestOptions options) { + return with(options); + } + + // === Operations === + + /** + * listDefinitions a preferenceDefinition using immutable params (executes immediately) - returns + * raw Response. + */ + Response listDefinitionsRaw(PreferenceDefinitionListDefinitionsParams params) + throws ChargebeeException { + + return get( + "preferenceDefinition", + "listDefinitions", + "/preferences/definitions", + params != null ? params.toQueryParams() : null); + } + + /** + * listDefinitions a preferenceDefinition using raw JSON payload (executes immediately) - returns + * raw Response. + */ + Response listDefinitionsRaw(String jsonPayload) throws ChargebeeException { + + throw new UnsupportedOperationException("JSON payload not supported for GET operations"); + } + + public PreferenceDefinitionListDefinitionsResponse listDefinitions( + PreferenceDefinitionListDefinitionsParams params) throws ChargebeeException { + Response response = listDefinitionsRaw(params); + + return PreferenceDefinitionListDefinitionsResponse.fromJson( + response.getBodyAsString(), response); + } + + /** Async variant of listDefinitions for preferenceDefinition with params. */ + public CompletableFuture listDefinitionsAsync( + PreferenceDefinitionListDefinitionsParams params) { + + return getAsync( + "preferenceDefinition", + "listDefinitions", + "/preferences/definitions", + params != null ? params.toQueryParams() : null) + .thenApply( + response -> + PreferenceDefinitionListDefinitionsResponse.fromJson( + response.getBodyAsString(), response)); + } +} diff --git a/src/main/java/com/chargebee/v4/services/PreferenceService.java b/src/main/java/com/chargebee/v4/services/PreferenceService.java new file mode 100644 index 00000000..513b0481 --- /dev/null +++ b/src/main/java/com/chargebee/v4/services/PreferenceService.java @@ -0,0 +1,113 @@ +/* + * This file is auto-generated by Chargebee. + * For more information on how to make changes to this file, please see the README. + * Reach out to dx@chargebee.com for any questions. + * Copyright 2025 Chargebee Inc. + */ + +package com.chargebee.v4.services; + +import com.chargebee.v4.client.ChargebeeClient; +import com.chargebee.v4.client.request.RequestOptions; +import com.chargebee.v4.exceptions.ChargebeeException; +import com.chargebee.v4.transport.Response; +import java.util.concurrent.CompletableFuture; + +import com.chargebee.v4.models.preference.params.PreferenceListParams; + +import com.chargebee.v4.models.preference.params.PreferenceUpsertParams; + +import com.chargebee.v4.models.preference.responses.PreferenceListResponse; + +import com.chargebee.v4.models.preference.responses.PreferenceUpsertResponse; + +public final class PreferenceService extends BaseService { + + private final ServiceConfig config; + + public PreferenceService(ChargebeeClient client) { + super(client); + this.config = ServiceConfig.defaultConfig(); + } + + private PreferenceService(ChargebeeClient client, RequestOptions options) { + super(client, options); + this.config = ServiceConfig.defaultConfig(); + } + + private PreferenceService(ChargebeeClient client, RequestOptions options, ServiceConfig config) { + super(client, options); + this.config = config; + } + + @Override + PreferenceService with(RequestOptions newOptions) { + return new PreferenceService(client, newOptions, config); + } + + /** + * Apply per-request options for this service instance. Users can chain .withOptions or .options + * to set headers and other options. + */ + public PreferenceService withOptions(RequestOptions options) { + return with(options); + } + + // === Operations === + + /** list a preference using immutable params (executes immediately) - returns raw Response. */ + Response listRaw(PreferenceListParams params) throws ChargebeeException { + + return get( + "preference", "list", "/preferences", params != null ? params.toQueryParams() : null); + } + + /** list a preference using raw JSON payload (executes immediately) - returns raw Response. */ + Response listRaw(String jsonPayload) throws ChargebeeException { + + throw new UnsupportedOperationException("JSON payload not supported for GET operations"); + } + + public PreferenceListResponse list(PreferenceListParams params) throws ChargebeeException { + Response response = listRaw(params); + + return PreferenceListResponse.fromJson(response.getBodyAsString(), response); + } + + /** Async variant of list for preference with params. */ + public CompletableFuture listAsync(PreferenceListParams params) { + + return getAsync( + "preference", "list", "/preferences", params != null ? params.toQueryParams() : null) + .thenApply( + response -> PreferenceListResponse.fromJson(response.getBodyAsString(), response)); + } + + /** upsert a preference using immutable params (executes immediately) - returns raw Response. */ + Response upsertRaw(PreferenceUpsertParams params) throws ChargebeeException { + + return post( + "preference", "upsert", "/preferences", params != null ? params.toFormData() : null); + } + + /** upsert a preference using raw JSON payload (executes immediately) - returns raw Response. */ + Response upsertRaw(String jsonPayload) throws ChargebeeException { + + return postJson("preference", "upsert", "/preferences", jsonPayload); + } + + public PreferenceUpsertResponse upsert(PreferenceUpsertParams params) throws ChargebeeException { + Response response = upsertRaw(params); + + return PreferenceUpsertResponse.fromJson(response.getBodyAsString(), response); + } + + /** Async variant of upsert for preference with params. */ + public CompletableFuture upsertAsync(PreferenceUpsertParams params) { + + return postAsync( + "preference", "upsert", "/preferences", params != null ? params.toFormData() : null) + .thenApply( + response -> PreferenceUpsertResponse.fromJson(response.getBodyAsString(), response)); + } +}