001
002package com.commercetools.api.models.subscription;
003
004import java.util.*;
005import java.util.function.Function;
006
007import javax.annotation.Nullable;
008
009import io.vrap.rmf.base.client.Builder;
010import io.vrap.rmf.base.client.utils.Generated;
011
012/**
013 * SubscriptionBuilder
014 * <hr>
015 * Example to create an instance using the builder pattern
016 * <div class=code-example>
017 * <pre><code class='java'>
018 *     Subscription subscription = Subscription.builder()
019 *             .id("{id}")
020 *             .version(0.3)
021 *             .createdAt(ZonedDateTime.parse("2022-01-01T12:00:00.301Z"))
022 *             .lastModifiedAt(ZonedDateTime.parse("2022-01-01T12:00:00.301Z"))
023 *             .plusChanges(changesBuilder -> changesBuilder)
024 *             .destination(destinationBuilder -> destinationBuilder)
025 *             .plusMessages(messagesBuilder -> messagesBuilder)
026 *             .format(formatBuilder -> formatBuilder)
027 *             .status(SubscriptionHealthStatus.HEALTHY)
028 *             .build()
029 * </code></pre>
030 * </div>
031 */
032@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
033public class SubscriptionBuilder implements Builder<Subscription> {
034
035    private String id;
036
037    private Long version;
038
039    private java.time.ZonedDateTime createdAt;
040
041    private java.time.ZonedDateTime lastModifiedAt;
042
043    @Nullable
044    private com.commercetools.api.models.common.LastModifiedBy lastModifiedBy;
045
046    @Nullable
047    private com.commercetools.api.models.common.CreatedBy createdBy;
048
049    private java.util.List<com.commercetools.api.models.subscription.ChangeSubscription> changes;
050
051    private com.commercetools.api.models.subscription.Destination destination;
052
053    @Nullable
054    private String key;
055
056    private java.util.List<com.commercetools.api.models.subscription.MessageSubscription> messages;
057
058    private com.commercetools.api.models.subscription.DeliveryFormat format;
059
060    private com.commercetools.api.models.subscription.SubscriptionHealthStatus status;
061
062    /**
063     *  <p>Unique identifier of the Subscription.</p>
064     * @param id value to be set
065     * @return Builder
066     */
067
068    public SubscriptionBuilder id(final String id) {
069        this.id = id;
070        return this;
071    }
072
073    /**
074     *  <p>Current version of the Subscription.</p>
075     * @param version value to be set
076     * @return Builder
077     */
078
079    public SubscriptionBuilder version(final Long version) {
080        this.version = version;
081        return this;
082    }
083
084    /**
085     *  <p>Date and time (UTC) the Subscription was initially created.</p>
086     * @param createdAt value to be set
087     * @return Builder
088     */
089
090    public SubscriptionBuilder createdAt(final java.time.ZonedDateTime createdAt) {
091        this.createdAt = createdAt;
092        return this;
093    }
094
095    /**
096     *  <p>Date and time (UTC) the Subscription was last modified.</p>
097     * @param lastModifiedAt value to be set
098     * @return Builder
099     */
100
101    public SubscriptionBuilder lastModifiedAt(final java.time.ZonedDateTime lastModifiedAt) {
102        this.lastModifiedAt = lastModifiedAt;
103        return this;
104    }
105
106    /**
107     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
108     * @param builder function to build the lastModifiedBy value
109     * @return Builder
110     */
111
112    public SubscriptionBuilder lastModifiedBy(
113            Function<com.commercetools.api.models.common.LastModifiedByBuilder, com.commercetools.api.models.common.LastModifiedByBuilder> builder) {
114        this.lastModifiedBy = builder.apply(com.commercetools.api.models.common.LastModifiedByBuilder.of()).build();
115        return this;
116    }
117
118    /**
119     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
120     * @param builder function to build the lastModifiedBy value
121     * @return Builder
122     */
123
124    public SubscriptionBuilder withLastModifiedBy(
125            Function<com.commercetools.api.models.common.LastModifiedByBuilder, com.commercetools.api.models.common.LastModifiedBy> builder) {
126        this.lastModifiedBy = builder.apply(com.commercetools.api.models.common.LastModifiedByBuilder.of());
127        return this;
128    }
129
130    /**
131     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
132     * @param lastModifiedBy value to be set
133     * @return Builder
134     */
135
136    public SubscriptionBuilder lastModifiedBy(
137            @Nullable final com.commercetools.api.models.common.LastModifiedBy lastModifiedBy) {
138        this.lastModifiedBy = lastModifiedBy;
139        return this;
140    }
141
142    /**
143     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
144     * @param builder function to build the createdBy value
145     * @return Builder
146     */
147
148    public SubscriptionBuilder createdBy(
149            Function<com.commercetools.api.models.common.CreatedByBuilder, com.commercetools.api.models.common.CreatedByBuilder> builder) {
150        this.createdBy = builder.apply(com.commercetools.api.models.common.CreatedByBuilder.of()).build();
151        return this;
152    }
153
154    /**
155     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
156     * @param builder function to build the createdBy value
157     * @return Builder
158     */
159
160    public SubscriptionBuilder withCreatedBy(
161            Function<com.commercetools.api.models.common.CreatedByBuilder, com.commercetools.api.models.common.CreatedBy> builder) {
162        this.createdBy = builder.apply(com.commercetools.api.models.common.CreatedByBuilder.of());
163        return this;
164    }
165
166    /**
167     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
168     * @param createdBy value to be set
169     * @return Builder
170     */
171
172    public SubscriptionBuilder createdBy(@Nullable final com.commercetools.api.models.common.CreatedBy createdBy) {
173        this.createdBy = createdBy;
174        return this;
175    }
176
177    /**
178     *  <p>Change notifications subscribed to.</p>
179     * @param changes value to be set
180     * @return Builder
181     */
182
183    public SubscriptionBuilder changes(final com.commercetools.api.models.subscription.ChangeSubscription... changes) {
184        this.changes = new ArrayList<>(Arrays.asList(changes));
185        return this;
186    }
187
188    /**
189     *  <p>Change notifications subscribed to.</p>
190     * @param changes value to be set
191     * @return Builder
192     */
193
194    public SubscriptionBuilder changes(
195            final java.util.List<com.commercetools.api.models.subscription.ChangeSubscription> changes) {
196        this.changes = changes;
197        return this;
198    }
199
200    /**
201     *  <p>Change notifications subscribed to.</p>
202     * @param changes value to be set
203     * @return Builder
204     */
205
206    public SubscriptionBuilder plusChanges(
207            final com.commercetools.api.models.subscription.ChangeSubscription... changes) {
208        if (this.changes == null) {
209            this.changes = new ArrayList<>();
210        }
211        this.changes.addAll(Arrays.asList(changes));
212        return this;
213    }
214
215    /**
216     *  <p>Change notifications subscribed to.</p>
217     * @param builder function to build the changes value
218     * @return Builder
219     */
220
221    public SubscriptionBuilder plusChanges(
222            Function<com.commercetools.api.models.subscription.ChangeSubscriptionBuilder, com.commercetools.api.models.subscription.ChangeSubscriptionBuilder> builder) {
223        if (this.changes == null) {
224            this.changes = new ArrayList<>();
225        }
226        this.changes
227                .add(builder.apply(com.commercetools.api.models.subscription.ChangeSubscriptionBuilder.of()).build());
228        return this;
229    }
230
231    /**
232     *  <p>Change notifications subscribed to.</p>
233     * @param builder function to build the changes value
234     * @return Builder
235     */
236
237    public SubscriptionBuilder withChanges(
238            Function<com.commercetools.api.models.subscription.ChangeSubscriptionBuilder, com.commercetools.api.models.subscription.ChangeSubscriptionBuilder> builder) {
239        this.changes = new ArrayList<>();
240        this.changes
241                .add(builder.apply(com.commercetools.api.models.subscription.ChangeSubscriptionBuilder.of()).build());
242        return this;
243    }
244
245    /**
246     *  <p>Change notifications subscribed to.</p>
247     * @param builder function to build the changes value
248     * @return Builder
249     */
250
251    public SubscriptionBuilder addChanges(
252            Function<com.commercetools.api.models.subscription.ChangeSubscriptionBuilder, com.commercetools.api.models.subscription.ChangeSubscription> builder) {
253        return plusChanges(builder.apply(com.commercetools.api.models.subscription.ChangeSubscriptionBuilder.of()));
254    }
255
256    /**
257     *  <p>Change notifications subscribed to.</p>
258     * @param builder function to build the changes value
259     * @return Builder
260     */
261
262    public SubscriptionBuilder setChanges(
263            Function<com.commercetools.api.models.subscription.ChangeSubscriptionBuilder, com.commercetools.api.models.subscription.ChangeSubscription> builder) {
264        return changes(builder.apply(com.commercetools.api.models.subscription.ChangeSubscriptionBuilder.of()));
265    }
266
267    /**
268     *  <p>Messaging service to which the messages are to be sent.</p>
269     * @param destination value to be set
270     * @return Builder
271     */
272
273    public SubscriptionBuilder destination(final com.commercetools.api.models.subscription.Destination destination) {
274        this.destination = destination;
275        return this;
276    }
277
278    /**
279     *  <p>Messaging service to which the messages are to be sent.</p>
280     * @param builder function to build the destination value
281     * @return Builder
282     */
283
284    public SubscriptionBuilder destination(
285            Function<com.commercetools.api.models.subscription.DestinationBuilder, Builder<? extends com.commercetools.api.models.subscription.Destination>> builder) {
286        this.destination = builder.apply(com.commercetools.api.models.subscription.DestinationBuilder.of()).build();
287        return this;
288    }
289
290    /**
291     *  <p>User-defined unique identifier of the Subscription.</p>
292     * @param key value to be set
293     * @return Builder
294     */
295
296    public SubscriptionBuilder key(@Nullable final String key) {
297        this.key = key;
298        return this;
299    }
300
301    /**
302     *  <p>Messages subscribed to.</p>
303     * @param messages value to be set
304     * @return Builder
305     */
306
307    public SubscriptionBuilder messages(
308            final com.commercetools.api.models.subscription.MessageSubscription... messages) {
309        this.messages = new ArrayList<>(Arrays.asList(messages));
310        return this;
311    }
312
313    /**
314     *  <p>Messages subscribed to.</p>
315     * @param messages value to be set
316     * @return Builder
317     */
318
319    public SubscriptionBuilder messages(
320            final java.util.List<com.commercetools.api.models.subscription.MessageSubscription> messages) {
321        this.messages = messages;
322        return this;
323    }
324
325    /**
326     *  <p>Messages subscribed to.</p>
327     * @param messages value to be set
328     * @return Builder
329     */
330
331    public SubscriptionBuilder plusMessages(
332            final com.commercetools.api.models.subscription.MessageSubscription... messages) {
333        if (this.messages == null) {
334            this.messages = new ArrayList<>();
335        }
336        this.messages.addAll(Arrays.asList(messages));
337        return this;
338    }
339
340    /**
341     *  <p>Messages subscribed to.</p>
342     * @param builder function to build the messages value
343     * @return Builder
344     */
345
346    public SubscriptionBuilder plusMessages(
347            Function<com.commercetools.api.models.subscription.MessageSubscriptionBuilder, com.commercetools.api.models.subscription.MessageSubscriptionBuilder> builder) {
348        if (this.messages == null) {
349            this.messages = new ArrayList<>();
350        }
351        this.messages
352                .add(builder.apply(com.commercetools.api.models.subscription.MessageSubscriptionBuilder.of()).build());
353        return this;
354    }
355
356    /**
357     *  <p>Messages subscribed to.</p>
358     * @param builder function to build the messages value
359     * @return Builder
360     */
361
362    public SubscriptionBuilder withMessages(
363            Function<com.commercetools.api.models.subscription.MessageSubscriptionBuilder, com.commercetools.api.models.subscription.MessageSubscriptionBuilder> builder) {
364        this.messages = new ArrayList<>();
365        this.messages
366                .add(builder.apply(com.commercetools.api.models.subscription.MessageSubscriptionBuilder.of()).build());
367        return this;
368    }
369
370    /**
371     *  <p>Messages subscribed to.</p>
372     * @param builder function to build the messages value
373     * @return Builder
374     */
375
376    public SubscriptionBuilder addMessages(
377            Function<com.commercetools.api.models.subscription.MessageSubscriptionBuilder, com.commercetools.api.models.subscription.MessageSubscription> builder) {
378        return plusMessages(builder.apply(com.commercetools.api.models.subscription.MessageSubscriptionBuilder.of()));
379    }
380
381    /**
382     *  <p>Messages subscribed to.</p>
383     * @param builder function to build the messages value
384     * @return Builder
385     */
386
387    public SubscriptionBuilder setMessages(
388            Function<com.commercetools.api.models.subscription.MessageSubscriptionBuilder, com.commercetools.api.models.subscription.MessageSubscription> builder) {
389        return messages(builder.apply(com.commercetools.api.models.subscription.MessageSubscriptionBuilder.of()));
390    }
391
392    /**
393     *  <p>Format in which the payload is delivered.</p>
394     * @param format value to be set
395     * @return Builder
396     */
397
398    public SubscriptionBuilder format(final com.commercetools.api.models.subscription.DeliveryFormat format) {
399        this.format = format;
400        return this;
401    }
402
403    /**
404     *  <p>Format in which the payload is delivered.</p>
405     * @param builder function to build the format value
406     * @return Builder
407     */
408
409    public SubscriptionBuilder format(
410            Function<com.commercetools.api.models.subscription.DeliveryFormatBuilder, Builder<? extends com.commercetools.api.models.subscription.DeliveryFormat>> builder) {
411        this.format = builder.apply(com.commercetools.api.models.subscription.DeliveryFormatBuilder.of()).build();
412        return this;
413    }
414
415    /**
416     *  <p>Status of the Subscription.</p>
417     * @param status value to be set
418     * @return Builder
419     */
420
421    public SubscriptionBuilder status(final com.commercetools.api.models.subscription.SubscriptionHealthStatus status) {
422        this.status = status;
423        return this;
424    }
425
426    /**
427     *  <p>Unique identifier of the Subscription.</p>
428     * @return id
429     */
430
431    public String getId() {
432        return this.id;
433    }
434
435    /**
436     *  <p>Current version of the Subscription.</p>
437     * @return version
438     */
439
440    public Long getVersion() {
441        return this.version;
442    }
443
444    /**
445     *  <p>Date and time (UTC) the Subscription was initially created.</p>
446     * @return createdAt
447     */
448
449    public java.time.ZonedDateTime getCreatedAt() {
450        return this.createdAt;
451    }
452
453    /**
454     *  <p>Date and time (UTC) the Subscription was last modified.</p>
455     * @return lastModifiedAt
456     */
457
458    public java.time.ZonedDateTime getLastModifiedAt() {
459        return this.lastModifiedAt;
460    }
461
462    /**
463     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
464     * @return lastModifiedBy
465     */
466
467    @Nullable
468    public com.commercetools.api.models.common.LastModifiedBy getLastModifiedBy() {
469        return this.lastModifiedBy;
470    }
471
472    /**
473     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
474     * @return createdBy
475     */
476
477    @Nullable
478    public com.commercetools.api.models.common.CreatedBy getCreatedBy() {
479        return this.createdBy;
480    }
481
482    /**
483     *  <p>Change notifications subscribed to.</p>
484     * @return changes
485     */
486
487    public java.util.List<com.commercetools.api.models.subscription.ChangeSubscription> getChanges() {
488        return this.changes;
489    }
490
491    /**
492     *  <p>Messaging service to which the messages are to be sent.</p>
493     * @return destination
494     */
495
496    public com.commercetools.api.models.subscription.Destination getDestination() {
497        return this.destination;
498    }
499
500    /**
501     *  <p>User-defined unique identifier of the Subscription.</p>
502     * @return key
503     */
504
505    @Nullable
506    public String getKey() {
507        return this.key;
508    }
509
510    /**
511     *  <p>Messages subscribed to.</p>
512     * @return messages
513     */
514
515    public java.util.List<com.commercetools.api.models.subscription.MessageSubscription> getMessages() {
516        return this.messages;
517    }
518
519    /**
520     *  <p>Format in which the payload is delivered.</p>
521     * @return format
522     */
523
524    public com.commercetools.api.models.subscription.DeliveryFormat getFormat() {
525        return this.format;
526    }
527
528    /**
529     *  <p>Status of the Subscription.</p>
530     * @return status
531     */
532
533    public com.commercetools.api.models.subscription.SubscriptionHealthStatus getStatus() {
534        return this.status;
535    }
536
537    /**
538     * builds Subscription with checking for non-null required values
539     * @return Subscription
540     */
541    public Subscription build() {
542        Objects.requireNonNull(id, Subscription.class + ": id is missing");
543        Objects.requireNonNull(version, Subscription.class + ": version is missing");
544        Objects.requireNonNull(createdAt, Subscription.class + ": createdAt is missing");
545        Objects.requireNonNull(lastModifiedAt, Subscription.class + ": lastModifiedAt is missing");
546        Objects.requireNonNull(changes, Subscription.class + ": changes is missing");
547        Objects.requireNonNull(destination, Subscription.class + ": destination is missing");
548        Objects.requireNonNull(messages, Subscription.class + ": messages is missing");
549        Objects.requireNonNull(format, Subscription.class + ": format is missing");
550        Objects.requireNonNull(status, Subscription.class + ": status is missing");
551        return new SubscriptionImpl(id, version, createdAt, lastModifiedAt, lastModifiedBy, createdBy, changes,
552            destination, key, messages, format, status);
553    }
554
555    /**
556     * builds Subscription without checking for non-null required values
557     * @return Subscription
558     */
559    public Subscription buildUnchecked() {
560        return new SubscriptionImpl(id, version, createdAt, lastModifiedAt, lastModifiedBy, createdBy, changes,
561            destination, key, messages, format, status);
562    }
563
564    /**
565     * factory method for an instance of SubscriptionBuilder
566     * @return builder
567     */
568    public static SubscriptionBuilder of() {
569        return new SubscriptionBuilder();
570    }
571
572    /**
573     * create builder for Subscription instance
574     * @param template instance with prefilled values for the builder
575     * @return builder
576     */
577    public static SubscriptionBuilder of(final Subscription template) {
578        SubscriptionBuilder builder = new SubscriptionBuilder();
579        builder.id = template.getId();
580        builder.version = template.getVersion();
581        builder.createdAt = template.getCreatedAt();
582        builder.lastModifiedAt = template.getLastModifiedAt();
583        builder.lastModifiedBy = template.getLastModifiedBy();
584        builder.createdBy = template.getCreatedBy();
585        builder.changes = template.getChanges();
586        builder.destination = template.getDestination();
587        builder.key = template.getKey();
588        builder.messages = template.getMessages();
589        builder.format = template.getFormat();
590        builder.status = template.getStatus();
591        return builder;
592    }
593
594}