001
002package com.commercetools.api.models.shipping_method;
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 * ShippingRateDraftBuilder
014 * <hr>
015 * Example to create an instance using the builder pattern
016 * <div class=code-example>
017 * <pre><code class='java'>
018 *     ShippingRateDraft shippingRateDraft = ShippingRateDraft.builder()
019 *             .price(priceBuilder -> priceBuilder)
020 *             .build()
021 * </code></pre>
022 * </div>
023 */
024@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
025public class ShippingRateDraftBuilder implements Builder<ShippingRateDraft> {
026
027    private com.commercetools.api.models.common.Money price;
028
029    @Nullable
030    private com.commercetools.api.models.common.Money freeAbove;
031
032    @Nullable
033    private java.util.List<com.commercetools.api.models.shipping_method.ShippingRatePriceTier> tiers;
034
035    /**
036     *  <p>Money value of the ShippingRate.</p>
037     * @param builder function to build the price value
038     * @return Builder
039     */
040
041    public ShippingRateDraftBuilder price(
042            Function<com.commercetools.api.models.common.MoneyBuilder, com.commercetools.api.models.common.MoneyBuilder> builder) {
043        this.price = builder.apply(com.commercetools.api.models.common.MoneyBuilder.of()).build();
044        return this;
045    }
046
047    /**
048     *  <p>Money value of the ShippingRate.</p>
049     * @param builder function to build the price value
050     * @return Builder
051     */
052
053    public ShippingRateDraftBuilder withPrice(
054            Function<com.commercetools.api.models.common.MoneyBuilder, com.commercetools.api.models.common.Money> builder) {
055        this.price = builder.apply(com.commercetools.api.models.common.MoneyBuilder.of());
056        return this;
057    }
058
059    /**
060     *  <p>Money value of the ShippingRate.</p>
061     * @param price value to be set
062     * @return Builder
063     */
064
065    public ShippingRateDraftBuilder price(final com.commercetools.api.models.common.Money price) {
066        this.price = price;
067        return this;
068    }
069
070    /**
071     *  <p>Shipping is free if the sum of the (Custom) Line Item Prices reaches the specified value.</p>
072     * @param builder function to build the freeAbove value
073     * @return Builder
074     */
075
076    public ShippingRateDraftBuilder freeAbove(
077            Function<com.commercetools.api.models.common.MoneyBuilder, com.commercetools.api.models.common.MoneyBuilder> builder) {
078        this.freeAbove = builder.apply(com.commercetools.api.models.common.MoneyBuilder.of()).build();
079        return this;
080    }
081
082    /**
083     *  <p>Shipping is free if the sum of the (Custom) Line Item Prices reaches the specified value.</p>
084     * @param builder function to build the freeAbove value
085     * @return Builder
086     */
087
088    public ShippingRateDraftBuilder withFreeAbove(
089            Function<com.commercetools.api.models.common.MoneyBuilder, com.commercetools.api.models.common.Money> builder) {
090        this.freeAbove = builder.apply(com.commercetools.api.models.common.MoneyBuilder.of());
091        return this;
092    }
093
094    /**
095     *  <p>Shipping is free if the sum of the (Custom) Line Item Prices reaches the specified value.</p>
096     * @param freeAbove value to be set
097     * @return Builder
098     */
099
100    public ShippingRateDraftBuilder freeAbove(@Nullable final com.commercetools.api.models.common.Money freeAbove) {
101        this.freeAbove = freeAbove;
102        return this;
103    }
104
105    /**
106     *  <p>Price tiers for the ShippingRate.</p>
107     * @param tiers value to be set
108     * @return Builder
109     */
110
111    public ShippingRateDraftBuilder tiers(
112            @Nullable final com.commercetools.api.models.shipping_method.ShippingRatePriceTier... tiers) {
113        this.tiers = new ArrayList<>(Arrays.asList(tiers));
114        return this;
115    }
116
117    /**
118     *  <p>Price tiers for the ShippingRate.</p>
119     * @param tiers value to be set
120     * @return Builder
121     */
122
123    public ShippingRateDraftBuilder tiers(
124            @Nullable final java.util.List<com.commercetools.api.models.shipping_method.ShippingRatePriceTier> tiers) {
125        this.tiers = tiers;
126        return this;
127    }
128
129    /**
130     *  <p>Price tiers for the ShippingRate.</p>
131     * @param tiers value to be set
132     * @return Builder
133     */
134
135    public ShippingRateDraftBuilder plusTiers(
136            @Nullable final com.commercetools.api.models.shipping_method.ShippingRatePriceTier... tiers) {
137        if (this.tiers == null) {
138            this.tiers = new ArrayList<>();
139        }
140        this.tiers.addAll(Arrays.asList(tiers));
141        return this;
142    }
143
144    /**
145     *  <p>Price tiers for the ShippingRate.</p>
146     * @param builder function to build the tiers value
147     * @return Builder
148     */
149
150    public ShippingRateDraftBuilder plusTiers(
151            Function<com.commercetools.api.models.shipping_method.ShippingRatePriceTierBuilder, Builder<? extends com.commercetools.api.models.shipping_method.ShippingRatePriceTier>> builder) {
152        if (this.tiers == null) {
153            this.tiers = new ArrayList<>();
154        }
155        this.tiers.add(
156            builder.apply(com.commercetools.api.models.shipping_method.ShippingRatePriceTierBuilder.of()).build());
157        return this;
158    }
159
160    /**
161     *  <p>Price tiers for the ShippingRate.</p>
162     * @param builder function to build the tiers value
163     * @return Builder
164     */
165
166    public ShippingRateDraftBuilder withTiers(
167            Function<com.commercetools.api.models.shipping_method.ShippingRatePriceTierBuilder, Builder<? extends com.commercetools.api.models.shipping_method.ShippingRatePriceTier>> builder) {
168        this.tiers = new ArrayList<>();
169        this.tiers.add(
170            builder.apply(com.commercetools.api.models.shipping_method.ShippingRatePriceTierBuilder.of()).build());
171        return this;
172    }
173
174    /**
175     *  <p>Money value of the ShippingRate.</p>
176     * @return price
177     */
178
179    public com.commercetools.api.models.common.Money getPrice() {
180        return this.price;
181    }
182
183    /**
184     *  <p>Shipping is free if the sum of the (Custom) Line Item Prices reaches the specified value.</p>
185     * @return freeAbove
186     */
187
188    @Nullable
189    public com.commercetools.api.models.common.Money getFreeAbove() {
190        return this.freeAbove;
191    }
192
193    /**
194     *  <p>Price tiers for the ShippingRate.</p>
195     * @return tiers
196     */
197
198    @Nullable
199    public java.util.List<com.commercetools.api.models.shipping_method.ShippingRatePriceTier> getTiers() {
200        return this.tiers;
201    }
202
203    /**
204     * builds ShippingRateDraft with checking for non-null required values
205     * @return ShippingRateDraft
206     */
207    public ShippingRateDraft build() {
208        Objects.requireNonNull(price, ShippingRateDraft.class + ": price is missing");
209        return new ShippingRateDraftImpl(price, freeAbove, tiers);
210    }
211
212    /**
213     * builds ShippingRateDraft without checking for non-null required values
214     * @return ShippingRateDraft
215     */
216    public ShippingRateDraft buildUnchecked() {
217        return new ShippingRateDraftImpl(price, freeAbove, tiers);
218    }
219
220    /**
221     * factory method for an instance of ShippingRateDraftBuilder
222     * @return builder
223     */
224    public static ShippingRateDraftBuilder of() {
225        return new ShippingRateDraftBuilder();
226    }
227
228    /**
229     * create builder for ShippingRateDraft instance
230     * @param template instance with prefilled values for the builder
231     * @return builder
232     */
233    public static ShippingRateDraftBuilder of(final ShippingRateDraft template) {
234        ShippingRateDraftBuilder builder = new ShippingRateDraftBuilder();
235        builder.price = template.getPrice();
236        builder.freeAbove = template.getFreeAbove();
237        builder.tiers = template.getTiers();
238        return builder;
239    }
240
241}