/*
 * 支付宝开放平台API
 * 支付宝开放平台v3协议文档
 *
 * The version of the OpenAPI document: 2023-08-14
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


package com.alipay.v3.model;

import java.util.Objects;
import java.util.Arrays;
import com.alipay.v3.model.PaymentFixVoucher;
import com.alipay.v3.model.PaymentVoucherAvailableGoods;
import com.alipay.v3.model.PaymentVoucherAvailableMerchant;
import com.alipay.v3.model.PaymentVoucherValidPeriod;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.alipay.v3.JSON;

/**
 * PaymentVoucherUseRule
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class PaymentVoucherUseRule {
  public static final String SERIALIZED_NAME_AVAILABLE_APP_IDS = "available_app_ids";
  @SerializedName(SERIALIZED_NAME_AVAILABLE_APP_IDS)
  private List<String> availableAppIds = null;

  public static final String SERIALIZED_NAME_AVAILABLE_GOODS = "available_goods";
  @SerializedName(SERIALIZED_NAME_AVAILABLE_GOODS)
  private PaymentVoucherAvailableGoods availableGoods;

  public static final String SERIALIZED_NAME_AVAILABLE_MERCHANT = "available_merchant";
  @SerializedName(SERIALIZED_NAME_AVAILABLE_MERCHANT)
  private PaymentVoucherAvailableMerchant availableMerchant;

  public static final String SERIALIZED_NAME_AVAILABLE_STORE_IDS = "available_store_ids";
  @SerializedName(SERIALIZED_NAME_AVAILABLE_STORE_IDS)
  private List<String> availableStoreIds = null;

  public static final String SERIALIZED_NAME_FIX_VOUCHER = "fix_voucher";
  @SerializedName(SERIALIZED_NAME_FIX_VOUCHER)
  private PaymentFixVoucher fixVoucher;

  public static final String SERIALIZED_NAME_UNAVAILABLE_GOODS_IDS = "unavailable_goods_ids";
  @SerializedName(SERIALIZED_NAME_UNAVAILABLE_GOODS_IDS)
  private List<String> unavailableGoodsIds = null;

  public static final String SERIALIZED_NAME_USE_MODE = "use_mode";
  @SerializedName(SERIALIZED_NAME_USE_MODE)
  private String useMode;

  public static final String SERIALIZED_NAME_USE_URL = "use_url";
  @SerializedName(SERIALIZED_NAME_USE_URL)
  private String useUrl;

  public static final String SERIALIZED_NAME_VOUCHER_QUANTITY_LIMIT_PER_USER = "voucher_quantity_limit_per_user";
  @SerializedName(SERIALIZED_NAME_VOUCHER_QUANTITY_LIMIT_PER_USER)
  private Integer voucherQuantityLimitPerUser;

  public static final String SERIALIZED_NAME_VOUCHER_QUANTITY_LIMIT_PER_USER_PERIOD_TYPE = "voucher_quantity_limit_per_user_period_type";
  @SerializedName(SERIALIZED_NAME_VOUCHER_QUANTITY_LIMIT_PER_USER_PERIOD_TYPE)
  private String voucherQuantityLimitPerUserPeriodType;

  public static final String SERIALIZED_NAME_VOUCHER_VALID_PERIOD = "voucher_valid_period";
  @SerializedName(SERIALIZED_NAME_VOUCHER_VALID_PERIOD)
  private PaymentVoucherValidPeriod voucherValidPeriod;

  public PaymentVoucherUseRule() { 
  }

  public PaymentVoucherUseRule availableAppIds(List<String> availableAppIds) {
    
    this.availableAppIds = availableAppIds;
    return this;
  }

  public PaymentVoucherUseRule addAvailableAppIdsItem(String availableAppIdsItem) {
    if (this.availableAppIds == null) {
      this.availableAppIds = new ArrayList<>();
    }
    this.availableAppIds.add(availableAppIdsItem);
    return this;
  }

   /**
   * 可核销的支付宝小程序id  限制：  1、必须是支付宝小程序 2、如果包含重复的小程序id会自动进行去重操作。
   * @return availableAppIds
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "[\"2021238412323412\"]", value = "可核销的支付宝小程序id  限制：  1、必须是支付宝小程序 2、如果包含重复的小程序id会自动进行去重操作。")

  public List<String> getAvailableAppIds() {
    return availableAppIds;
  }


  public void setAvailableAppIds(List<String> availableAppIds) {
    this.availableAppIds = availableAppIds;
  }


  public PaymentVoucherUseRule availableGoods(PaymentVoucherAvailableGoods availableGoods) {
    
    this.availableGoods = availableGoods;
    return this;
  }

   /**
   * Get availableGoods
   * @return availableGoods
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public PaymentVoucherAvailableGoods getAvailableGoods() {
    return availableGoods;
  }


  public void setAvailableGoods(PaymentVoucherAvailableGoods availableGoods) {
    this.availableGoods = availableGoods;
  }


  public PaymentVoucherUseRule availableMerchant(PaymentVoucherAvailableMerchant availableMerchant) {
    
    this.availableMerchant = availableMerchant;
    return this;
  }

   /**
   * Get availableMerchant
   * @return availableMerchant
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public PaymentVoucherAvailableMerchant getAvailableMerchant() {
    return availableMerchant;
  }


  public void setAvailableMerchant(PaymentVoucherAvailableMerchant availableMerchant) {
    this.availableMerchant = availableMerchant;
  }


  public PaymentVoucherUseRule availableStoreIds(List<String> availableStoreIds) {
    
    this.availableStoreIds = availableStoreIds;
    return this;
  }

  public PaymentVoucherUseRule addAvailableStoreIdsItem(String availableStoreIdsItem) {
    if (this.availableStoreIds == null) {
      this.availableStoreIds = new ArrayList<>();
    }
    this.availableStoreIds.add(availableStoreIdsItem);
    return this;
  }

   /**
   * 可核销支付门店id。 限制：  1、available_store_ids中的门店id必须是支付宝门店id。  2、available_store_ids如果包含重复的门店id会自动进行去重操作。
   * @return availableStoreIds
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "[\"2018051000502000000011111111\",\"2018040200502000000011111111\",\"2018062800502000000022271997\"]", value = "可核销支付门店id。 限制：  1、available_store_ids中的门店id必须是支付宝门店id。  2、available_store_ids如果包含重复的门店id会自动进行去重操作。")

  public List<String> getAvailableStoreIds() {
    return availableStoreIds;
  }


  public void setAvailableStoreIds(List<String> availableStoreIds) {
    this.availableStoreIds = availableStoreIds;
  }


  public PaymentVoucherUseRule fixVoucher(PaymentFixVoucher fixVoucher) {
    
    this.fixVoucher = fixVoucher;
    return this;
  }

   /**
   * Get fixVoucher
   * @return fixVoucher
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public PaymentFixVoucher getFixVoucher() {
    return fixVoucher;
  }


  public void setFixVoucher(PaymentFixVoucher fixVoucher) {
    this.fixVoucher = fixVoucher;
  }


  public PaymentVoucherUseRule unavailableGoodsIds(List<String> unavailableGoodsIds) {
    
    this.unavailableGoodsIds = unavailableGoodsIds;
    return this;
  }

  public PaymentVoucherUseRule addUnavailableGoodsIdsItem(String unavailableGoodsIdsItem) {
    if (this.unavailableGoodsIds == null) {
      this.unavailableGoodsIds = new ArrayList<>();
    }
    this.unavailableGoodsIds.add(unavailableGoodsIdsItem);
    return this;
  }

   /**
   * 不可核销商品编码，商家自定义商品编码。当用户支付时，交易中的商品编码和支付券配置的商品编码有任一匹配时，不可以使用优惠券。  限制: 1、available_goods与unavailable_goods_ids只能二选一或者同时为空
   * @return unavailableGoodsIds
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "['apple-03','apple-04']", value = "不可核销商品编码，商家自定义商品编码。当用户支付时，交易中的商品编码和支付券配置的商品编码有任一匹配时，不可以使用优惠券。  限制: 1、available_goods与unavailable_goods_ids只能二选一或者同时为空")

  public List<String> getUnavailableGoodsIds() {
    return unavailableGoodsIds;
  }


  public void setUnavailableGoodsIds(List<String> unavailableGoodsIds) {
    this.unavailableGoodsIds = unavailableGoodsIds;
  }


  public PaymentVoucherUseRule useMode(String useMode) {
    
    this.useMode = useMode;
    return this;
  }

   /**
   * 核销跳转方式,默认CAN_USE(详情页展示可使用按钮)
   * @return useMode
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "SELF_LINK", value = "核销跳转方式,默认CAN_USE(详情页展示可使用按钮)")

  public String getUseMode() {
    return useMode;
  }


  public void setUseMode(String useMode) {
    this.useMode = useMode;
  }


  public PaymentVoucherUseRule useUrl(String useUrl) {
    
    this.useUrl = useUrl;
    return this;
  }

   /**
   * 核销跳转链接 限制: 1、只有use_mode为SELF_LINK时该值有效且必传。 2、核销跳转链接必须是支付宝小程序链接。
   * @return useUrl
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "alipays://platformapi/startapp?appId=201911136XXXXX&noneExit=true", value = "核销跳转链接 限制: 1、只有use_mode为SELF_LINK时该值有效且必传。 2、核销跳转链接必须是支付宝小程序链接。")

  public String getUseUrl() {
    return useUrl;
  }


  public void setUseUrl(String useUrl) {
    this.useUrl = useUrl;
  }


  public PaymentVoucherUseRule voucherQuantityLimitPerUser(Integer voucherQuantityLimitPerUser) {
    
    this.voucherQuantityLimitPerUser = voucherQuantityLimitPerUser;
    return this;
  }

   /**
   * 每个支付宝账号的核销次数限制。 默认不限制
   * @return voucherQuantityLimitPerUser
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "1", value = "每个支付宝账号的核销次数限制。 默认不限制")

  public Integer getVoucherQuantityLimitPerUser() {
    return voucherQuantityLimitPerUser;
  }


  public void setVoucherQuantityLimitPerUser(Integer voucherQuantityLimitPerUser) {
    this.voucherQuantityLimitPerUser = voucherQuantityLimitPerUser;
  }


  public PaymentVoucherUseRule voucherQuantityLimitPerUserPeriodType(String voucherQuantityLimitPerUserPeriodType) {
    
    this.voucherQuantityLimitPerUserPeriodType = voucherQuantityLimitPerUserPeriodType;
    return this;
  }

   /**
   * 核销次数限制周期配置。默认值LIFE_CYCLE表示限制每个支付宝账号在整个活动期间核销次数。
   * @return voucherQuantityLimitPerUserPeriodType
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(example = "DAY", value = "核销次数限制周期配置。默认值LIFE_CYCLE表示限制每个支付宝账号在整个活动期间核销次数。")

  public String getVoucherQuantityLimitPerUserPeriodType() {
    return voucherQuantityLimitPerUserPeriodType;
  }


  public void setVoucherQuantityLimitPerUserPeriodType(String voucherQuantityLimitPerUserPeriodType) {
    this.voucherQuantityLimitPerUserPeriodType = voucherQuantityLimitPerUserPeriodType;
  }


  public PaymentVoucherUseRule voucherValidPeriod(PaymentVoucherValidPeriod voucherValidPeriod) {
    
    this.voucherValidPeriod = voucherValidPeriod;
    return this;
  }

   /**
   * Get voucherValidPeriod
   * @return voucherValidPeriod
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(value = "")

  public PaymentVoucherValidPeriod getVoucherValidPeriod() {
    return voucherValidPeriod;
  }


  public void setVoucherValidPeriod(PaymentVoucherValidPeriod voucherValidPeriod) {
    this.voucherValidPeriod = voucherValidPeriod;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    PaymentVoucherUseRule paymentVoucherUseRule = (PaymentVoucherUseRule) o;
    return Objects.equals(this.availableAppIds, paymentVoucherUseRule.availableAppIds) &&
        Objects.equals(this.availableGoods, paymentVoucherUseRule.availableGoods) &&
        Objects.equals(this.availableMerchant, paymentVoucherUseRule.availableMerchant) &&
        Objects.equals(this.availableStoreIds, paymentVoucherUseRule.availableStoreIds) &&
        Objects.equals(this.fixVoucher, paymentVoucherUseRule.fixVoucher) &&
        Objects.equals(this.unavailableGoodsIds, paymentVoucherUseRule.unavailableGoodsIds) &&
        Objects.equals(this.useMode, paymentVoucherUseRule.useMode) &&
        Objects.equals(this.useUrl, paymentVoucherUseRule.useUrl) &&
        Objects.equals(this.voucherQuantityLimitPerUser, paymentVoucherUseRule.voucherQuantityLimitPerUser) &&
        Objects.equals(this.voucherQuantityLimitPerUserPeriodType, paymentVoucherUseRule.voucherQuantityLimitPerUserPeriodType) &&
        Objects.equals(this.voucherValidPeriod, paymentVoucherUseRule.voucherValidPeriod);
  }

  @Override
  public int hashCode() {
    return Objects.hash(availableAppIds, availableGoods, availableMerchant, availableStoreIds, fixVoucher, unavailableGoodsIds, useMode, useUrl, voucherQuantityLimitPerUser, voucherQuantityLimitPerUserPeriodType, voucherValidPeriod);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class PaymentVoucherUseRule {\n");
    sb.append("    availableAppIds: ").append(toIndentedString(availableAppIds)).append("\n");
    sb.append("    availableGoods: ").append(toIndentedString(availableGoods)).append("\n");
    sb.append("    availableMerchant: ").append(toIndentedString(availableMerchant)).append("\n");
    sb.append("    availableStoreIds: ").append(toIndentedString(availableStoreIds)).append("\n");
    sb.append("    fixVoucher: ").append(toIndentedString(fixVoucher)).append("\n");
    sb.append("    unavailableGoodsIds: ").append(toIndentedString(unavailableGoodsIds)).append("\n");
    sb.append("    useMode: ").append(toIndentedString(useMode)).append("\n");
    sb.append("    useUrl: ").append(toIndentedString(useUrl)).append("\n");
    sb.append("    voucherQuantityLimitPerUser: ").append(toIndentedString(voucherQuantityLimitPerUser)).append("\n");
    sb.append("    voucherQuantityLimitPerUserPeriodType: ").append(toIndentedString(voucherQuantityLimitPerUserPeriodType)).append("\n");
    sb.append("    voucherValidPeriod: ").append(toIndentedString(voucherValidPeriod)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }


  public static HashSet<String> openapiFields;
  public static HashSet<String> openapiRequiredFields;

  static {
    // a set of all properties/fields (JSON key names)
    openapiFields = new HashSet<String>();
    openapiFields.add("available_app_ids");
    openapiFields.add("available_goods");
    openapiFields.add("available_merchant");
    openapiFields.add("available_store_ids");
    openapiFields.add("fix_voucher");
    openapiFields.add("unavailable_goods_ids");
    openapiFields.add("use_mode");
    openapiFields.add("use_url");
    openapiFields.add("voucher_quantity_limit_per_user");
    openapiFields.add("voucher_quantity_limit_per_user_period_type");
    openapiFields.add("voucher_valid_period");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet<String>();
  }

 /**
  * Validates the JSON Object and throws an exception if issues found
  *
  * @param jsonObj JSON Object
  * @throws IOException if the JSON Object is invalid with respect to PaymentVoucherUseRule
  */
  public static void validateJsonObject(JsonObject jsonObj) throws IOException {
      if (jsonObj == null) {
        if (PaymentVoucherUseRule.openapiRequiredFields.isEmpty()) {
          return;
        } else { // has required fields
          throw new IllegalArgumentException(String.format("The required field(s) %s in PaymentVoucherUseRule is not found in the empty JSON string", PaymentVoucherUseRule.openapiRequiredFields.toString()));
        }
      }

      Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
      // check to see if the JSON string contains additional fields
      for (Entry<String, JsonElement> entry : entries) {
        if (!PaymentVoucherUseRule.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `PaymentVoucherUseRule` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
        }
      }
      // ensure the json data is an array
      if (jsonObj.get("available_app_ids") != null && !jsonObj.get("available_app_ids").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `available_app_ids` to be an array in the JSON string but got `%s`", jsonObj.get("available_app_ids").toString()));
      }
      // validate the optional field `available_goods`
      if (jsonObj.getAsJsonObject("available_goods") != null) {
        PaymentVoucherAvailableGoods.validateJsonObject(jsonObj.getAsJsonObject("available_goods"));
      }
      // validate the optional field `available_merchant`
      if (jsonObj.getAsJsonObject("available_merchant") != null) {
        PaymentVoucherAvailableMerchant.validateJsonObject(jsonObj.getAsJsonObject("available_merchant"));
      }
      // ensure the json data is an array
      if (jsonObj.get("available_store_ids") != null && !jsonObj.get("available_store_ids").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `available_store_ids` to be an array in the JSON string but got `%s`", jsonObj.get("available_store_ids").toString()));
      }
      // validate the optional field `fix_voucher`
      if (jsonObj.getAsJsonObject("fix_voucher") != null) {
        PaymentFixVoucher.validateJsonObject(jsonObj.getAsJsonObject("fix_voucher"));
      }
      // ensure the json data is an array
      if (jsonObj.get("unavailable_goods_ids") != null && !jsonObj.get("unavailable_goods_ids").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `unavailable_goods_ids` to be an array in the JSON string but got `%s`", jsonObj.get("unavailable_goods_ids").toString()));
      }
      if (jsonObj.get("use_mode") != null && !jsonObj.get("use_mode").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `use_mode` to be a primitive type in the JSON string but got `%s`", jsonObj.get("use_mode").toString()));
      }
      if (jsonObj.get("use_url") != null && !jsonObj.get("use_url").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `use_url` to be a primitive type in the JSON string but got `%s`", jsonObj.get("use_url").toString()));
      }
      if (jsonObj.get("voucher_quantity_limit_per_user_period_type") != null && !jsonObj.get("voucher_quantity_limit_per_user_period_type").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `voucher_quantity_limit_per_user_period_type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("voucher_quantity_limit_per_user_period_type").toString()));
      }
      // validate the optional field `voucher_valid_period`
      if (jsonObj.getAsJsonObject("voucher_valid_period") != null) {
        PaymentVoucherValidPeriod.validateJsonObject(jsonObj.getAsJsonObject("voucher_valid_period"));
      }
  }

  public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
    @SuppressWarnings("unchecked")
    @Override
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
       if (!PaymentVoucherUseRule.class.isAssignableFrom(type.getRawType())) {
         return null; // this class only serializes 'PaymentVoucherUseRule' and its subtypes
       }
       final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
       final TypeAdapter<PaymentVoucherUseRule> thisAdapter
                        = gson.getDelegateAdapter(this, TypeToken.get(PaymentVoucherUseRule.class));

       return (TypeAdapter<T>) new TypeAdapter<PaymentVoucherUseRule>() {
           @Override
           public void write(JsonWriter out, PaymentVoucherUseRule value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             elementAdapter.write(out, obj);
           }

           @Override
           public PaymentVoucherUseRule read(JsonReader in) throws IOException {
             JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
             validateJsonObject(jsonObj);
             return thisAdapter.fromJsonTree(jsonObj);
           }

       }.nullSafe();
    }
  }

 /**
  * Create an instance of PaymentVoucherUseRule given an JSON string
  *
  * @param jsonString JSON string
  * @return An instance of PaymentVoucherUseRule
  * @throws IOException if the JSON string is invalid with respect to PaymentVoucherUseRule
  */
  public static PaymentVoucherUseRule fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, PaymentVoucherUseRule.class);
  }

 /**
  * Convert an instance of PaymentVoucherUseRule to an JSON string
  *
  * @return JSON string
  */
  public String toJson() {
    return JSON.getGson().toJson(this);
  }
}

