001
002package com.commercetools.api.models.discount_code;
003
004import java.time.*;
005import java.time.ZonedDateTime;
006import java.util.*;
007import java.util.function.Function;
008import java.util.stream.Collectors;
009
010import javax.annotation.Nullable;
011import javax.validation.Valid;
012import javax.validation.constraints.NotNull;
013
014import com.commercetools.api.models.cart_discount.CartDiscountReference;
015import com.commercetools.api.models.common.BaseResource;
016import com.commercetools.api.models.common.CreatedBy;
017import com.commercetools.api.models.common.LastModifiedBy;
018import com.commercetools.api.models.common.LocalizedString;
019import com.commercetools.api.models.common.Reference;
020import com.commercetools.api.models.type.CustomFields;
021import com.fasterxml.jackson.annotation.*;
022import com.fasterxml.jackson.databind.annotation.*;
023
024import io.vrap.rmf.base.client.utils.Generated;
025
026/**
027 * DiscountCode
028 *
029 * <hr>
030 * Example to create an instance using the builder pattern
031 * <div class=code-example>
032 * <pre><code class='java'>
033 *     DiscountCode discountCode = DiscountCode.builder()
034 *             .id("{id}")
035 *             .version(0.3)
036 *             .createdAt(ZonedDateTime.parse("2022-01-01T12:00:00.301Z"))
037 *             .lastModifiedAt(ZonedDateTime.parse("2022-01-01T12:00:00.301Z"))
038 *             .code("{code}")
039 *             .plusCartDiscounts(cartDiscountsBuilder -> cartDiscountsBuilder)
040 *             .isActive(true)
041 *             .plusReferences(referencesBuilder -> referencesBuilder)
042 *             .plusGroups(groupsBuilder -> groupsBuilder)
043 *             .build()
044 * </code></pre>
045 * </div>
046 */
047@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
048@JsonDeserialize(as = DiscountCodeImpl.class)
049public interface DiscountCode
050        extends BaseResource, DiscountCodeMixin, com.commercetools.api.models.DomainResource<DiscountCode>,
051        com.commercetools.api.models.Referencable<DiscountCode>,
052        com.commercetools.api.models.ResourceIdentifiable<DiscountCode>,
053        com.commercetools.api.models.Customizable<DiscountCode> {
054
055    /**
056     *  <p>Unique identifier of the DiscountCode.</p>
057     * @return id
058     */
059    @NotNull
060    @JsonProperty("id")
061    public String getId();
062
063    /**
064     *  <p>Current version of the DiscountCode.</p>
065     * @return version
066     */
067    @NotNull
068    @JsonProperty("version")
069    public Long getVersion();
070
071    /**
072     *  <p>Date and time (UTC) the DiscountCode was initially created.</p>
073     * @return createdAt
074     */
075    @NotNull
076    @JsonProperty("createdAt")
077    public ZonedDateTime getCreatedAt();
078
079    /**
080     *  <p>Date and time (UTC) the DiscountCode was last updated.</p>
081     * @return lastModifiedAt
082     */
083    @NotNull
084    @JsonProperty("lastModifiedAt")
085    public ZonedDateTime getLastModifiedAt();
086
087    /**
088     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
089     * @return lastModifiedBy
090     */
091    @Valid
092    @JsonProperty("lastModifiedBy")
093    public LastModifiedBy getLastModifiedBy();
094
095    /**
096     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
097     * @return createdBy
098     */
099    @Valid
100    @JsonProperty("createdBy")
101    public CreatedBy getCreatedBy();
102
103    /**
104     *  <p>Name of the DiscountCode.</p>
105     * @return name
106     */
107    @Valid
108    @JsonProperty("name")
109    public LocalizedString getName();
110
111    /**
112     *  <p>Description of the DiscountCode.</p>
113     * @return description
114     */
115    @Valid
116    @JsonProperty("description")
117    public LocalizedString getDescription();
118
119    /**
120     *  <p>User-defined unique identifier of the DiscountCode added to the Cart to apply the related CartDiscounts.</p>
121     * @return code
122     */
123    @NotNull
124    @JsonProperty("code")
125    public String getCode();
126
127    /**
128     *  <p>Reference to CartDiscounts that can be applied to the Cart once the DiscountCode is applied.</p>
129     * @return cartDiscounts
130     */
131    @NotNull
132    @Valid
133    @JsonProperty("cartDiscounts")
134    public List<CartDiscountReference> getCartDiscounts();
135
136    /**
137     *  <p>DiscountCode can only be applied to Carts that match this predicate.</p>
138     * @return cartPredicate
139     */
140
141    @JsonProperty("cartPredicate")
142    public String getCartPredicate();
143
144    /**
145     *  <p>Indicates if the DiscountCode is active and can be applied to the Cart.</p>
146     * @return isActive
147     */
148    @NotNull
149    @JsonProperty("isActive")
150    public Boolean getIsActive();
151
152    /**
153     *  <p>Array generated from the Cart predicate. It contains the references of all the resources that are addressed in the predicate.</p>
154     * @return references
155     */
156    @NotNull
157    @Valid
158    @JsonProperty("references")
159    public List<Reference> getReferences();
160
161    /**
162     *  <p>Number of times the DiscountCode can be applied. DiscountCode application is counted at the time of Order creation or edit. However, Order cancellation or deletion does not decrement the count.</p>
163     * @return maxApplications
164     */
165
166    @JsonProperty("maxApplications")
167    public Long getMaxApplications();
168
169    /**
170     *  <p>Number of times the DiscountCode can be applied per Customer (anonymous Carts are not supported). DiscountCode application is counted at the time of Order creation or edit. However, Order cancellation or deletion does not decrement the count.</p>
171     * @return maxApplicationsPerCustomer
172     */
173
174    @JsonProperty("maxApplicationsPerCustomer")
175    public Long getMaxApplicationsPerCustomer();
176
177    /**
178     *  <p>Custom Fields of the DiscountCode.</p>
179     * @return custom
180     */
181    @Valid
182    @JsonProperty("custom")
183    public CustomFields getCustom();
184
185    /**
186     *  <p>Groups to which the DiscountCode belongs to.</p>
187     * @return groups
188     */
189    @NotNull
190    @JsonProperty("groups")
191    public List<String> getGroups();
192
193    /**
194     *  <p>Date and time (UTC) from which the DiscountCode is effective.</p>
195     * @return validFrom
196     */
197
198    @JsonProperty("validFrom")
199    public ZonedDateTime getValidFrom();
200
201    /**
202     *  <p>Date and time (UTC) until which the DiscountCode is effective.</p>
203     * @return validUntil
204     */
205
206    @JsonProperty("validUntil")
207    public ZonedDateTime getValidUntil();
208
209    /**
210     *  <p>Used and managed by the API and must not be used in customer logic. The value can change at any time due to internal and external factors.</p>
211     * @return applicationVersion
212     */
213
214    @JsonProperty("applicationVersion")
215    public Long getApplicationVersion();
216
217    /**
218     *  <p>Unique identifier of the DiscountCode.</p>
219     * @param id value to be set
220     */
221
222    public void setId(final String id);
223
224    /**
225     *  <p>Current version of the DiscountCode.</p>
226     * @param version value to be set
227     */
228
229    public void setVersion(final Long version);
230
231    /**
232     *  <p>Date and time (UTC) the DiscountCode was initially created.</p>
233     * @param createdAt value to be set
234     */
235
236    public void setCreatedAt(final ZonedDateTime createdAt);
237
238    /**
239     *  <p>Date and time (UTC) the DiscountCode was last updated.</p>
240     * @param lastModifiedAt value to be set
241     */
242
243    public void setLastModifiedAt(final ZonedDateTime lastModifiedAt);
244
245    /**
246     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
247     * @param lastModifiedBy value to be set
248     */
249
250    public void setLastModifiedBy(final LastModifiedBy lastModifiedBy);
251
252    /**
253     *  <p>Present on resources created after 1 February 2019 except for events not tracked.</p>
254     * @param createdBy value to be set
255     */
256
257    public void setCreatedBy(final CreatedBy createdBy);
258
259    /**
260     *  <p>Name of the DiscountCode.</p>
261     * @param name value to be set
262     */
263
264    public void setName(final LocalizedString name);
265
266    /**
267     *  <p>Description of the DiscountCode.</p>
268     * @param description value to be set
269     */
270
271    public void setDescription(final LocalizedString description);
272
273    /**
274     *  <p>User-defined unique identifier of the DiscountCode added to the Cart to apply the related CartDiscounts.</p>
275     * @param code value to be set
276     */
277
278    public void setCode(final String code);
279
280    /**
281     *  <p>Reference to CartDiscounts that can be applied to the Cart once the DiscountCode is applied.</p>
282     * @param cartDiscounts values to be set
283     */
284
285    @JsonIgnore
286    public void setCartDiscounts(final CartDiscountReference... cartDiscounts);
287
288    /**
289     *  <p>Reference to CartDiscounts that can be applied to the Cart once the DiscountCode is applied.</p>
290     * @param cartDiscounts values to be set
291     */
292
293    public void setCartDiscounts(final List<CartDiscountReference> cartDiscounts);
294
295    /**
296     *  <p>DiscountCode can only be applied to Carts that match this predicate.</p>
297     * @param cartPredicate value to be set
298     */
299
300    public void setCartPredicate(final String cartPredicate);
301
302    /**
303     *  <p>Indicates if the DiscountCode is active and can be applied to the Cart.</p>
304     * @param isActive value to be set
305     */
306
307    public void setIsActive(final Boolean isActive);
308
309    /**
310     *  <p>Array generated from the Cart predicate. It contains the references of all the resources that are addressed in the predicate.</p>
311     * @param references values to be set
312     */
313
314    @JsonIgnore
315    public void setReferences(final Reference... references);
316
317    /**
318     *  <p>Array generated from the Cart predicate. It contains the references of all the resources that are addressed in the predicate.</p>
319     * @param references values to be set
320     */
321
322    public void setReferences(final List<Reference> references);
323
324    /**
325     *  <p>Number of times the DiscountCode can be applied. DiscountCode application is counted at the time of Order creation or edit. However, Order cancellation or deletion does not decrement the count.</p>
326     * @param maxApplications value to be set
327     */
328
329    public void setMaxApplications(final Long maxApplications);
330
331    /**
332     *  <p>Number of times the DiscountCode can be applied per Customer (anonymous Carts are not supported). DiscountCode application is counted at the time of Order creation or edit. However, Order cancellation or deletion does not decrement the count.</p>
333     * @param maxApplicationsPerCustomer value to be set
334     */
335
336    public void setMaxApplicationsPerCustomer(final Long maxApplicationsPerCustomer);
337
338    /**
339     *  <p>Custom Fields of the DiscountCode.</p>
340     * @param custom value to be set
341     */
342
343    public void setCustom(final CustomFields custom);
344
345    /**
346     *  <p>Groups to which the DiscountCode belongs to.</p>
347     * @param groups values to be set
348     */
349
350    @JsonIgnore
351    public void setGroups(final String... groups);
352
353    /**
354     *  <p>Groups to which the DiscountCode belongs to.</p>
355     * @param groups values to be set
356     */
357
358    public void setGroups(final List<String> groups);
359
360    /**
361     *  <p>Date and time (UTC) from which the DiscountCode is effective.</p>
362     * @param validFrom value to be set
363     */
364
365    public void setValidFrom(final ZonedDateTime validFrom);
366
367    /**
368     *  <p>Date and time (UTC) until which the DiscountCode is effective.</p>
369     * @param validUntil value to be set
370     */
371
372    public void setValidUntil(final ZonedDateTime validUntil);
373
374    /**
375     *  <p>Used and managed by the API and must not be used in customer logic. The value can change at any time due to internal and external factors.</p>
376     * @param applicationVersion value to be set
377     */
378
379    public void setApplicationVersion(final Long applicationVersion);
380
381    /**
382     * factory method
383     * @return instance of DiscountCode
384     */
385    public static DiscountCode of() {
386        return new DiscountCodeImpl();
387    }
388
389    /**
390     * factory method to create a shallow copy DiscountCode
391     * @param template instance to be copied
392     * @return copy instance
393     */
394    public static DiscountCode of(final DiscountCode template) {
395        DiscountCodeImpl instance = new DiscountCodeImpl();
396        instance.setId(template.getId());
397        instance.setVersion(template.getVersion());
398        instance.setCreatedAt(template.getCreatedAt());
399        instance.setLastModifiedAt(template.getLastModifiedAt());
400        instance.setLastModifiedBy(template.getLastModifiedBy());
401        instance.setCreatedBy(template.getCreatedBy());
402        instance.setName(template.getName());
403        instance.setDescription(template.getDescription());
404        instance.setCode(template.getCode());
405        instance.setCartDiscounts(template.getCartDiscounts());
406        instance.setCartPredicate(template.getCartPredicate());
407        instance.setIsActive(template.getIsActive());
408        instance.setReferences(template.getReferences());
409        instance.setMaxApplications(template.getMaxApplications());
410        instance.setMaxApplicationsPerCustomer(template.getMaxApplicationsPerCustomer());
411        instance.setCustom(template.getCustom());
412        instance.setGroups(template.getGroups());
413        instance.setValidFrom(template.getValidFrom());
414        instance.setValidUntil(template.getValidUntil());
415        instance.setApplicationVersion(template.getApplicationVersion());
416        return instance;
417    }
418
419    /**
420     * factory method to create a deep copy of DiscountCode
421     * @param template instance to be copied
422     * @return copy instance
423     */
424    @Nullable
425    public static DiscountCode deepCopy(@Nullable final DiscountCode template) {
426        if (template == null) {
427            return null;
428        }
429        DiscountCodeImpl instance = new DiscountCodeImpl();
430        instance.setId(template.getId());
431        instance.setVersion(template.getVersion());
432        instance.setCreatedAt(template.getCreatedAt());
433        instance.setLastModifiedAt(template.getLastModifiedAt());
434        instance.setLastModifiedBy(
435            com.commercetools.api.models.common.LastModifiedBy.deepCopy(template.getLastModifiedBy()));
436        instance.setCreatedBy(com.commercetools.api.models.common.CreatedBy.deepCopy(template.getCreatedBy()));
437        instance.setName(com.commercetools.api.models.common.LocalizedString.deepCopy(template.getName()));
438        instance.setDescription(
439            com.commercetools.api.models.common.LocalizedString.deepCopy(template.getDescription()));
440        instance.setCode(template.getCode());
441        instance.setCartDiscounts(Optional.ofNullable(template.getCartDiscounts())
442                .map(t -> t.stream()
443                        .map(com.commercetools.api.models.cart_discount.CartDiscountReference::deepCopy)
444                        .collect(Collectors.toList()))
445                .orElse(null));
446        instance.setCartPredicate(template.getCartPredicate());
447        instance.setIsActive(template.getIsActive());
448        instance.setReferences(Optional.ofNullable(template.getReferences())
449                .map(t -> t.stream()
450                        .map(com.commercetools.api.models.common.Reference::deepCopy)
451                        .collect(Collectors.toList()))
452                .orElse(null));
453        instance.setMaxApplications(template.getMaxApplications());
454        instance.setMaxApplicationsPerCustomer(template.getMaxApplicationsPerCustomer());
455        instance.setCustom(com.commercetools.api.models.type.CustomFields.deepCopy(template.getCustom()));
456        instance.setGroups(Optional.ofNullable(template.getGroups()).map(ArrayList::new).orElse(null));
457        instance.setValidFrom(template.getValidFrom());
458        instance.setValidUntil(template.getValidUntil());
459        instance.setApplicationVersion(template.getApplicationVersion());
460        return instance;
461    }
462
463    /**
464     * builder factory method for DiscountCode
465     * @return builder
466     */
467    public static DiscountCodeBuilder builder() {
468        return DiscountCodeBuilder.of();
469    }
470
471    /**
472     * create builder for DiscountCode instance
473     * @param template instance with prefilled values for the builder
474     * @return builder
475     */
476    public static DiscountCodeBuilder builder(final DiscountCode template) {
477        return DiscountCodeBuilder.of(template);
478    }
479
480    /**
481     * accessor map function
482     * @param <T> mapped type
483     * @param helper function to map the object
484     * @return mapped value
485     */
486    default <T> T withDiscountCode(Function<DiscountCode, T> helper) {
487        return helper.apply(this);
488    }
489
490    public static com.commercetools.api.models.common.ReferenceTypeId referenceTypeId() {
491        return com.commercetools.api.models.common.ReferenceTypeId.DISCOUNT_CODE;
492    }
493
494    /**
495     * gives a TypeReference for usage with Jackson DataBind
496     * @return TypeReference
497     */
498    public static com.fasterxml.jackson.core.type.TypeReference<DiscountCode> typeReference() {
499        return new com.fasterxml.jackson.core.type.TypeReference<DiscountCode>() {
500            @Override
501            public String toString() {
502                return "TypeReference<DiscountCode>";
503            }
504        };
505    }
506}