001
002package com.commercetools.history.models.common;
003
004import java.time.*;
005import java.util.*;
006import java.util.function.Function;
007import java.util.stream.Collectors;
008
009import javax.annotation.Nullable;
010import javax.validation.Valid;
011import javax.validation.constraints.NotNull;
012
013import com.fasterxml.jackson.annotation.*;
014import com.fasterxml.jackson.databind.annotation.*;
015
016import io.vrap.rmf.base.client.utils.Generated;
017
018/**
019 *  <p>Shape of the value for <code>addTaxRate</code> and <code>removeTaxRate</code> actions</p>
020 *
021 * <hr>
022 * Example to create an instance using the builder pattern
023 * <div class=code-example>
024 * <pre><code class='java'>
025 *     TaxRate taxRate = TaxRate.builder()
026 *             .id("{id}")
027 *             .name("{name}")
028 *             .amount(1)
029 *             .includedInPrice(true)
030 *             .country("{country}")
031 *             .state("{state}")
032 *             .plusSubRates(subRatesBuilder -> subRatesBuilder)
033 *             .build()
034 * </code></pre>
035 * </div>
036 */
037@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
038@JsonDeserialize(as = TaxRateImpl.class)
039public interface TaxRate {
040
041    /**
042     *  <p>The ID is always set if the tax rate is part of a TaxCategory. The external tax rates in a Cart do not contain an <code>id</code>.</p>
043     * @return id
044     */
045    @NotNull
046    @JsonProperty("id")
047    public String getId();
048
049    /**
050     *
051     * @return name
052     */
053    @NotNull
054    @JsonProperty("name")
055    public String getName();
056
057    /**
058     *  <p>Percentage in the range of [0..1]. The sum of the amounts of all <code>subRates</code>, if there are any.</p>
059     * @return amount
060     */
061    @NotNull
062    @JsonProperty("amount")
063    public Integer getAmount();
064
065    /**
066     *
067     * @return includedInPrice
068     */
069    @NotNull
070    @JsonProperty("includedInPrice")
071    public Boolean getIncludedInPrice();
072
073    /**
074     *  <p>Two-digit country code as per ISO 3166-1 alpha-2.</p>
075     * @return country
076     */
077    @NotNull
078    @JsonProperty("country")
079    public String getCountry();
080
081    /**
082     *  <p>The state in the country</p>
083     * @return state
084     */
085    @NotNull
086    @JsonProperty("state")
087    public String getState();
088
089    /**
090     *
091     * @return subRates
092     */
093    @NotNull
094    @Valid
095    @JsonProperty("subRates")
096    public List<SubRate> getSubRates();
097
098    /**
099     *  <p>The ID is always set if the tax rate is part of a TaxCategory. The external tax rates in a Cart do not contain an <code>id</code>.</p>
100     * @param id value to be set
101     */
102
103    public void setId(final String id);
104
105    /**
106     * set name
107     * @param name value to be set
108     */
109
110    public void setName(final String name);
111
112    /**
113     *  <p>Percentage in the range of [0..1]. The sum of the amounts of all <code>subRates</code>, if there are any.</p>
114     * @param amount value to be set
115     */
116
117    public void setAmount(final Integer amount);
118
119    /**
120     * set includedInPrice
121     * @param includedInPrice value to be set
122     */
123
124    public void setIncludedInPrice(final Boolean includedInPrice);
125
126    /**
127     *  <p>Two-digit country code as per ISO 3166-1 alpha-2.</p>
128     * @param country value to be set
129     */
130
131    public void setCountry(final String country);
132
133    /**
134     *  <p>The state in the country</p>
135     * @param state value to be set
136     */
137
138    public void setState(final String state);
139
140    /**
141     * set subRates
142     * @param subRates values to be set
143     */
144
145    @JsonIgnore
146    public void setSubRates(final SubRate... subRates);
147
148    /**
149     * set subRates
150     * @param subRates values to be set
151     */
152
153    public void setSubRates(final List<SubRate> subRates);
154
155    /**
156     * factory method
157     * @return instance of TaxRate
158     */
159    public static TaxRate of() {
160        return new TaxRateImpl();
161    }
162
163    /**
164     * factory method to create a shallow copy TaxRate
165     * @param template instance to be copied
166     * @return copy instance
167     */
168    public static TaxRate of(final TaxRate template) {
169        TaxRateImpl instance = new TaxRateImpl();
170        instance.setId(template.getId());
171        instance.setName(template.getName());
172        instance.setAmount(template.getAmount());
173        instance.setIncludedInPrice(template.getIncludedInPrice());
174        instance.setCountry(template.getCountry());
175        instance.setState(template.getState());
176        instance.setSubRates(template.getSubRates());
177        return instance;
178    }
179
180    /**
181     * factory method to create a deep copy of TaxRate
182     * @param template instance to be copied
183     * @return copy instance
184     */
185    @Nullable
186    public static TaxRate deepCopy(@Nullable final TaxRate template) {
187        if (template == null) {
188            return null;
189        }
190        TaxRateImpl instance = new TaxRateImpl();
191        instance.setId(template.getId());
192        instance.setName(template.getName());
193        instance.setAmount(template.getAmount());
194        instance.setIncludedInPrice(template.getIncludedInPrice());
195        instance.setCountry(template.getCountry());
196        instance.setState(template.getState());
197        instance.setSubRates(Optional.ofNullable(template.getSubRates())
198                .map(t -> t.stream()
199                        .map(com.commercetools.history.models.common.SubRate::deepCopy)
200                        .collect(Collectors.toList()))
201                .orElse(null));
202        return instance;
203    }
204
205    /**
206     * builder factory method for TaxRate
207     * @return builder
208     */
209    public static TaxRateBuilder builder() {
210        return TaxRateBuilder.of();
211    }
212
213    /**
214     * create builder for TaxRate instance
215     * @param template instance with prefilled values for the builder
216     * @return builder
217     */
218    public static TaxRateBuilder builder(final TaxRate template) {
219        return TaxRateBuilder.of(template);
220    }
221
222    /**
223     * accessor map function
224     * @param <T> mapped type
225     * @param helper function to map the object
226     * @return mapped value
227     */
228    default <T> T withTaxRate(Function<TaxRate, T> helper) {
229        return helper.apply(this);
230    }
231
232    /**
233     * gives a TypeReference for usage with Jackson DataBind
234     * @return TypeReference
235     */
236    public static com.fasterxml.jackson.core.type.TypeReference<TaxRate> typeReference() {
237        return new com.fasterxml.jackson.core.type.TypeReference<TaxRate>() {
238            @Override
239            public String toString() {
240                return "TypeReference<TaxRate>";
241            }
242        };
243    }
244}