All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.segment.publicapi.models.DestinationMetadataActionV1 Maven / Gradle / Ivy

/*
 * Segment Public API
 * The Segment Public API helps you manage your Segment Workspaces and its resources. You can use the API to perform CRUD (create, read, update, delete) operations at no extra charge. This includes working with resources such as Sources, Destinations, Warehouses, Tracking Plans, and the Segment Destinations and Sources Catalogs.  All CRUD endpoints in the API follow REST conventions and use standard HTTP methods. Different URL endpoints represent different resources in a Workspace.  See the next sections for more information on how to use the Segment Public API. 
 *
 * The version of the OpenAPI document: 32.0.3
 * Contact: [email protected]
 *
 * 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.segment.publicapi.models;

import java.util.Objects;
import java.util.Arrays;
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 com.segment.publicapi.models.DestinationMetadataActionFieldV1;
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.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.segment.publicapi.JSON;

/**
 * Represents an Action, a building block of behavior that can be performed by the Destination.
 */
@ApiModel(description = "Represents an Action, a building block of behavior that can be performed by the Destination.")

public class DestinationMetadataActionV1 {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  private String id;

  public static final String SERIALIZED_NAME_SLUG = "slug";
  @SerializedName(SERIALIZED_NAME_SLUG)
  private String slug;

  public static final String SERIALIZED_NAME_NAME = "name";
  @SerializedName(SERIALIZED_NAME_NAME)
  private String name;

  public static final String SERIALIZED_NAME_DESCRIPTION = "description";
  @SerializedName(SERIALIZED_NAME_DESCRIPTION)
  private String description;

  /**
   * The platform on which this action runs.
   */
  @JsonAdapter(PlatformEnum.Adapter.class)
  public enum PlatformEnum {
    CLOUD("CLOUD"),
    
    MOBILE("MOBILE"),
    
    WEB("WEB");

    private String value;

    PlatformEnum(String value) {
      this.value = value;
    }

    public String getValue() {
      return value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }

    public static PlatformEnum fromValue(String value) {
      for (PlatformEnum b : PlatformEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

    public static class Adapter extends TypeAdapter {
      @Override
      public void write(final JsonWriter jsonWriter, final PlatformEnum enumeration) throws IOException {
        jsonWriter.value(enumeration.getValue());
      }

      @Override
      public PlatformEnum read(final JsonReader jsonReader) throws IOException {
        String value =  jsonReader.nextString();
        return PlatformEnum.fromValue(value);
      }
    }
  }

  public static final String SERIALIZED_NAME_PLATFORM = "platform";
  @SerializedName(SERIALIZED_NAME_PLATFORM)
  private PlatformEnum platform;

  public static final String SERIALIZED_NAME_HIDDEN = "hidden";
  @SerializedName(SERIALIZED_NAME_HIDDEN)
  private Boolean hidden;

  public static final String SERIALIZED_NAME_DEFAULT_TRIGGER = "defaultTrigger";
  @SerializedName(SERIALIZED_NAME_DEFAULT_TRIGGER)
  private String defaultTrigger;

  public static final String SERIALIZED_NAME_FIELDS = "fields";
  @SerializedName(SERIALIZED_NAME_FIELDS)
  private List fields = new ArrayList<>();

  public DestinationMetadataActionV1() {
  }

  public DestinationMetadataActionV1 id(String id) {
    
    this.id = id;
    return this;
  }

   /**
   * The primary key of the action.
   * @return id
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "The primary key of the action.")

  public String getId() {
    return id;
  }


  public void setId(String id) {
    this.id = id;
  }


  public DestinationMetadataActionV1 slug(String slug) {
    
    this.slug = slug;
    return this;
  }

   /**
   * A machine-readable key unique to the action definition.
   * @return slug
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "A machine-readable key unique to the action definition.")

  public String getSlug() {
    return slug;
  }


  public void setSlug(String slug) {
    this.slug = slug;
  }


  public DestinationMetadataActionV1 name(String name) {
    
    this.name = name;
    return this;
  }

   /**
   * A human-readable name for the action.
   * @return name
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "A human-readable name for the action.")

  public String getName() {
    return name;
  }


  public void setName(String name) {
    this.name = name;
  }


  public DestinationMetadataActionV1 description(String description) {
    
    this.description = description;
    return this;
  }

   /**
   * A human-readable description of the action. May include Markdown.
   * @return description
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "A human-readable description of the action. May include Markdown.")

  public String getDescription() {
    return description;
  }


  public void setDescription(String description) {
    this.description = description;
  }


  public DestinationMetadataActionV1 platform(PlatformEnum platform) {
    
    this.platform = platform;
    return this;
  }

   /**
   * The platform on which this action runs.
   * @return platform
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "The platform on which this action runs.")

  public PlatformEnum getPlatform() {
    return platform;
  }


  public void setPlatform(PlatformEnum platform) {
    this.platform = platform;
  }


  public DestinationMetadataActionV1 hidden(Boolean hidden) {
    
    this.hidden = hidden;
    return this;
  }

   /**
   * Whether the action should be hidden.
   * @return hidden
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "Whether the action should be hidden.")

  public Boolean getHidden() {
    return hidden;
  }


  public void setHidden(Boolean hidden) {
    this.hidden = hidden;
  }


  public DestinationMetadataActionV1 defaultTrigger(String defaultTrigger) {
    
    this.defaultTrigger = defaultTrigger;
    return this;
  }

   /**
   * The default value used as the trigger when connecting this action.
   * @return defaultTrigger
  **/
  @javax.annotation.Nullable
  @ApiModelProperty(required = true, value = "The default value used as the trigger when connecting this action.")

  public String getDefaultTrigger() {
    return defaultTrigger;
  }


  public void setDefaultTrigger(String defaultTrigger) {
    this.defaultTrigger = defaultTrigger;
  }


  public DestinationMetadataActionV1 fields(List fields) {
    
    this.fields = fields;
    return this;
  }

  public DestinationMetadataActionV1 addFieldsItem(DestinationMetadataActionFieldV1 fieldsItem) {
    this.fields.add(fieldsItem);
    return this;
  }

   /**
   * The fields expected in order to perform the action.
   * @return fields
  **/
  @javax.annotation.Nonnull
  @ApiModelProperty(required = true, value = "The fields expected in order to perform the action.")

  public List getFields() {
    return fields;
  }


  public void setFields(List fields) {
    this.fields = fields;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    DestinationMetadataActionV1 destinationMetadataActionV1 = (DestinationMetadataActionV1) o;
    return Objects.equals(this.id, destinationMetadataActionV1.id) &&
        Objects.equals(this.slug, destinationMetadataActionV1.slug) &&
        Objects.equals(this.name, destinationMetadataActionV1.name) &&
        Objects.equals(this.description, destinationMetadataActionV1.description) &&
        Objects.equals(this.platform, destinationMetadataActionV1.platform) &&
        Objects.equals(this.hidden, destinationMetadataActionV1.hidden) &&
        Objects.equals(this.defaultTrigger, destinationMetadataActionV1.defaultTrigger) &&
        Objects.equals(this.fields, destinationMetadataActionV1.fields);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, slug, name, description, platform, hidden, defaultTrigger, fields);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class DestinationMetadataActionV1 {\n");
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    slug: ").append(toIndentedString(slug)).append("\n");
    sb.append("    name: ").append(toIndentedString(name)).append("\n");
    sb.append("    description: ").append(toIndentedString(description)).append("\n");
    sb.append("    platform: ").append(toIndentedString(platform)).append("\n");
    sb.append("    hidden: ").append(toIndentedString(hidden)).append("\n");
    sb.append("    defaultTrigger: ").append(toIndentedString(defaultTrigger)).append("\n");
    sb.append("    fields: ").append(toIndentedString(fields)).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 openapiFields;
  public static HashSet openapiRequiredFields;

  static {
    // a set of all properties/fields (JSON key names)
    openapiFields = new HashSet();
    openapiFields.add("id");
    openapiFields.add("slug");
    openapiFields.add("name");
    openapiFields.add("description");
    openapiFields.add("platform");
    openapiFields.add("hidden");
    openapiFields.add("defaultTrigger");
    openapiFields.add("fields");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet();
    openapiRequiredFields.add("id");
    openapiRequiredFields.add("slug");
    openapiRequiredFields.add("name");
    openapiRequiredFields.add("description");
    openapiRequiredFields.add("platform");
    openapiRequiredFields.add("hidden");
    openapiRequiredFields.add("defaultTrigger");
    openapiRequiredFields.add("fields");
  }

 /**
  * 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 DestinationMetadataActionV1
  */
  public static void validateJsonObject(JsonObject jsonObj) throws IOException {
      if (jsonObj == null) {
        if (!DestinationMetadataActionV1.openapiRequiredFields.isEmpty()) { // has required fields but JSON object is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in DestinationMetadataActionV1 is not found in the empty JSON string", DestinationMetadataActionV1.openapiRequiredFields.toString()));
        }
      }

      Set> entries = jsonObj.entrySet();
      // check to see if the JSON string contains additional fields
      for (Entry entry : entries) {
        if (!DestinationMetadataActionV1.openapiFields.contains(entry.getKey())) {
          throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `DestinationMetadataActionV1` properties. JSON: %s", entry.getKey(), jsonObj.toString()));
        }
      }

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : DestinationMetadataActionV1.openapiRequiredFields) {
        if (jsonObj.get(requiredField) == null) {
          throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonObj.toString()));
        }
      }
      if (!jsonObj.get("id").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString()));
      }
      if (!jsonObj.get("slug").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `slug` to be a primitive type in the JSON string but got `%s`", jsonObj.get("slug").toString()));
      }
      if (!jsonObj.get("name").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `name` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name").toString()));
      }
      if (!jsonObj.get("description").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString()));
      }
      if (!jsonObj.get("platform").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `platform` to be a primitive type in the JSON string but got `%s`", jsonObj.get("platform").toString()));
      }
      if (!jsonObj.get("defaultTrigger").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `defaultTrigger` to be a primitive type in the JSON string but got `%s`", jsonObj.get("defaultTrigger").toString()));
      }
      // ensure the json data is an array
      if (!jsonObj.get("fields").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `fields` to be an array in the JSON string but got `%s`", jsonObj.get("fields").toString()));
      }

      JsonArray jsonArrayfields = jsonObj.getAsJsonArray("fields");
  }

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

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

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

       }.nullSafe();
    }
  }

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

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy