001package com.box.sdkgen.schemas.metadatacascadepolicy;
002
003import com.box.sdkgen.internal.NullableFieldTracker;
004import com.box.sdkgen.internal.SerializableObject;
005import com.box.sdkgen.serialization.json.EnumWrapper;
006import com.fasterxml.jackson.annotation.JsonFilter;
007import com.fasterxml.jackson.annotation.JsonProperty;
008import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
009import com.fasterxml.jackson.databind.annotation.JsonSerialize;
010import java.util.Objects;
011
012/**
013 * A metadata cascade policy automatically applies a metadata template instance to all the files and
014 * folders within the targeted folder.
015 */
016@JsonFilter("nullablePropertyFilter")
017public class MetadataCascadePolicy extends SerializableObject {
018
019  /** The ID of the metadata cascade policy object. */
020  protected final String id;
021
022  /** The value will always be `metadata_cascade_policy`. */
023  @JsonDeserialize(
024      using = MetadataCascadePolicyTypeField.MetadataCascadePolicyTypeFieldDeserializer.class)
025  @JsonSerialize(
026      using = MetadataCascadePolicyTypeField.MetadataCascadePolicyTypeFieldSerializer.class)
027  protected EnumWrapper<MetadataCascadePolicyTypeField> type;
028
029  /** The enterprise that owns this policy. */
030  @JsonProperty("owner_enterprise")
031  protected MetadataCascadePolicyOwnerEnterpriseField ownerEnterprise;
032
033  /** Represent the folder the policy is applied to. */
034  protected MetadataCascadePolicyParentField parent;
035
036  /**
037   * The scope of the metadata cascade policy can either be `global` or `enterprise_*`. The `global`
038   * scope is used for policies that are available to any Box enterprise. The `enterprise_*` scope
039   * represents policies that have been created within a specific enterprise, where `*` will be the
040   * ID of that enterprise.
041   */
042  protected String scope;
043
044  /**
045   * The key of the template that is cascaded down to the folder's children.
046   *
047   * <p>In many cases the template key is automatically derived of its display name, for example
048   * `Contract Template` would become `contractTemplate`. In some cases the creator of the template
049   * will have provided its own template key.
050   *
051   * <p>Please [list the templates for an enterprise][list], or get all instances on a [file][file]
052   * or [folder][folder] to inspect a template's key.
053   *
054   * <p>[list]: https://developer.box.com/reference/get-metadata-templates-enterprise [file]:
055   * https://developer.box.com/reference/get-files-id-metadata [folder]:
056   * https://developer.box.com/reference/get-folders-id-metadata
057   */
058  protected String templateKey;
059
060  public MetadataCascadePolicy(@JsonProperty("id") String id) {
061    super();
062    this.id = id;
063    this.type =
064        new EnumWrapper<MetadataCascadePolicyTypeField>(
065            MetadataCascadePolicyTypeField.METADATA_CASCADE_POLICY);
066  }
067
068  protected MetadataCascadePolicy(Builder builder) {
069    super();
070    this.id = builder.id;
071    this.type = builder.type;
072    this.ownerEnterprise = builder.ownerEnterprise;
073    this.parent = builder.parent;
074    this.scope = builder.scope;
075    this.templateKey = builder.templateKey;
076    markNullableFieldsAsSet(builder.getExplicitlySetNullableFields());
077  }
078
079  public String getId() {
080    return id;
081  }
082
083  public EnumWrapper<MetadataCascadePolicyTypeField> getType() {
084    return type;
085  }
086
087  public MetadataCascadePolicyOwnerEnterpriseField getOwnerEnterprise() {
088    return ownerEnterprise;
089  }
090
091  public MetadataCascadePolicyParentField getParent() {
092    return parent;
093  }
094
095  public String getScope() {
096    return scope;
097  }
098
099  public String getTemplateKey() {
100    return templateKey;
101  }
102
103  @Override
104  public boolean equals(Object o) {
105    if (this == o) {
106      return true;
107    }
108    if (o == null || getClass() != o.getClass()) {
109      return false;
110    }
111    MetadataCascadePolicy casted = (MetadataCascadePolicy) o;
112    return Objects.equals(id, casted.id)
113        && Objects.equals(type, casted.type)
114        && Objects.equals(ownerEnterprise, casted.ownerEnterprise)
115        && Objects.equals(parent, casted.parent)
116        && Objects.equals(scope, casted.scope)
117        && Objects.equals(templateKey, casted.templateKey);
118  }
119
120  @Override
121  public int hashCode() {
122    return Objects.hash(id, type, ownerEnterprise, parent, scope, templateKey);
123  }
124
125  @Override
126  public String toString() {
127    return "MetadataCascadePolicy{"
128        + "id='"
129        + id
130        + '\''
131        + ", "
132        + "type='"
133        + type
134        + '\''
135        + ", "
136        + "ownerEnterprise='"
137        + ownerEnterprise
138        + '\''
139        + ", "
140        + "parent='"
141        + parent
142        + '\''
143        + ", "
144        + "scope='"
145        + scope
146        + '\''
147        + ", "
148        + "templateKey='"
149        + templateKey
150        + '\''
151        + "}";
152  }
153
154  public static class Builder extends NullableFieldTracker {
155
156    protected final String id;
157
158    protected EnumWrapper<MetadataCascadePolicyTypeField> type;
159
160    protected MetadataCascadePolicyOwnerEnterpriseField ownerEnterprise;
161
162    protected MetadataCascadePolicyParentField parent;
163
164    protected String scope;
165
166    protected String templateKey;
167
168    public Builder(String id) {
169      super();
170      this.id = id;
171    }
172
173    public Builder type(MetadataCascadePolicyTypeField type) {
174      this.type = new EnumWrapper<MetadataCascadePolicyTypeField>(type);
175      return this;
176    }
177
178    public Builder type(EnumWrapper<MetadataCascadePolicyTypeField> type) {
179      this.type = type;
180      return this;
181    }
182
183    public Builder ownerEnterprise(MetadataCascadePolicyOwnerEnterpriseField ownerEnterprise) {
184      this.ownerEnterprise = ownerEnterprise;
185      return this;
186    }
187
188    public Builder parent(MetadataCascadePolicyParentField parent) {
189      this.parent = parent;
190      return this;
191    }
192
193    public Builder scope(String scope) {
194      this.scope = scope;
195      return this;
196    }
197
198    public Builder templateKey(String templateKey) {
199      this.templateKey = templateKey;
200      return this;
201    }
202
203    public MetadataCascadePolicy build() {
204      if (this.type == null) {
205        this.type =
206            new EnumWrapper<MetadataCascadePolicyTypeField>(
207                MetadataCascadePolicyTypeField.METADATA_CASCADE_POLICY);
208      }
209      return new MetadataCascadePolicy(this);
210    }
211  }
212}