001 002package com.commercetools.api.models.common; 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.channel.ChannelReference; 015import com.commercetools.api.models.customer_group.CustomerGroupReference; 016import com.commercetools.api.models.type.CustomFields; 017import com.fasterxml.jackson.annotation.*; 018import com.fasterxml.jackson.databind.annotation.*; 019 020import io.vrap.rmf.base.client.utils.Generated; 021 022/** 023 * <p>The representation for prices embedded in LineItems and in ProductVariants when the ProductPriceMode is <code>Embedded</code>. For the <code>Standalone</code> ProductPriceMode refer to StandalonePrice.</p> 024 * 025 * <hr> 026 * Example to create an instance using the builder pattern 027 * <div class=code-example> 028 * <pre><code class='java'> 029 * Price price = Price.builder() 030 * .id("{id}") 031 * .value(valueBuilder -> valueBuilder) 032 * .build() 033 * </code></pre> 034 * </div> 035 */ 036@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 037@JsonDeserialize(as = PriceImpl.class) 038public interface Price extends com.commercetools.api.models.Customizable<Price>, com.commercetools.api.models.WithKey { 039 040 /** 041 * <p>Unique identifier of this Price.</p> 042 * @return id 043 */ 044 @NotNull 045 @JsonProperty("id") 046 public String getId(); 047 048 /** 049 * <p>User-defined identifier of the Price. It is unique per ProductVariant.</p> 050 * @return key 051 */ 052 053 @JsonProperty("key") 054 public String getKey(); 055 056 /** 057 * <p>Money value of this Price.</p> 058 * @return value 059 */ 060 @NotNull 061 @Valid 062 @JsonProperty("value") 063 public TypedMoney getValue(); 064 065 /** 066 * <p>Country for which this Price is valid.</p> 067 * @return country 068 */ 069 070 @JsonProperty("country") 071 public String getCountry(); 072 073 /** 074 * <p>CustomerGroup for which this Price is valid.</p> 075 * @return customerGroup 076 */ 077 @Valid 078 @JsonProperty("customerGroup") 079 public CustomerGroupReference getCustomerGroup(); 080 081 /** 082 * <p><code>ProductDistribution</code> Channel for which this Price is valid.</p> 083 * @return channel 084 */ 085 @Valid 086 @JsonProperty("channel") 087 public ChannelReference getChannel(); 088 089 /** 090 * <p>Date and time from which this Price is valid.</p> 091 * @return validFrom 092 */ 093 094 @JsonProperty("validFrom") 095 public ZonedDateTime getValidFrom(); 096 097 /** 098 * <p>Date and time until this Price is valid. Prices that are no longer valid are not automatically removed, but they can be removed if necessary.</p> 099 * @return validUntil 100 */ 101 102 @JsonProperty("validUntil") 103 public ZonedDateTime getValidUntil(); 104 105 /** 106 * <p>Is set if a ProductDiscount has been applied. If set, the API uses the DiscountedPrice value for the Line Item Price selection. When a relative discount has been applied and the fraction part of the DiscountedPrice <code>value</code> is 0.5, the <code>value</code> is rounded in favor of the customer with half-down rounding.</p> 107 * @return discounted 108 */ 109 @Valid 110 @JsonProperty("discounted") 111 public DiscountedPrice getDiscounted(); 112 113 /** 114 * <p>Present if different Prices for certain LineItem quantities have been specified.</p> 115 * @return tiers 116 */ 117 @Valid 118 @JsonProperty("tiers") 119 public List<PriceTier> getTiers(); 120 121 /** 122 * <p>Custom Fields defined for the Price.</p> 123 * @return custom 124 */ 125 @Valid 126 @JsonProperty("custom") 127 public CustomFields getCustom(); 128 129 /** 130 * <p>Unique identifier of this Price.</p> 131 * @param id value to be set 132 */ 133 134 public void setId(final String id); 135 136 /** 137 * <p>User-defined identifier of the Price. It is unique per ProductVariant.</p> 138 * @param key value to be set 139 */ 140 141 public void setKey(final String key); 142 143 /** 144 * <p>Money value of this Price.</p> 145 * @param value value to be set 146 */ 147 148 public void setValue(final TypedMoney value); 149 150 /** 151 * <p>Country for which this Price is valid.</p> 152 * @param country value to be set 153 */ 154 155 public void setCountry(final String country); 156 157 /** 158 * <p>CustomerGroup for which this Price is valid.</p> 159 * @param customerGroup value to be set 160 */ 161 162 public void setCustomerGroup(final CustomerGroupReference customerGroup); 163 164 /** 165 * <p><code>ProductDistribution</code> Channel for which this Price is valid.</p> 166 * @param channel value to be set 167 */ 168 169 public void setChannel(final ChannelReference channel); 170 171 /** 172 * <p>Date and time from which this Price is valid.</p> 173 * @param validFrom value to be set 174 */ 175 176 public void setValidFrom(final ZonedDateTime validFrom); 177 178 /** 179 * <p>Date and time until this Price is valid. Prices that are no longer valid are not automatically removed, but they can be removed if necessary.</p> 180 * @param validUntil value to be set 181 */ 182 183 public void setValidUntil(final ZonedDateTime validUntil); 184 185 /** 186 * <p>Is set if a ProductDiscount has been applied. If set, the API uses the DiscountedPrice value for the Line Item Price selection. When a relative discount has been applied and the fraction part of the DiscountedPrice <code>value</code> is 0.5, the <code>value</code> is rounded in favor of the customer with half-down rounding.</p> 187 * @param discounted value to be set 188 */ 189 190 public void setDiscounted(final DiscountedPrice discounted); 191 192 /** 193 * <p>Present if different Prices for certain LineItem quantities have been specified.</p> 194 * @param tiers values to be set 195 */ 196 197 @JsonIgnore 198 public void setTiers(final PriceTier... tiers); 199 200 /** 201 * <p>Present if different Prices for certain LineItem quantities have been specified.</p> 202 * @param tiers values to be set 203 */ 204 205 public void setTiers(final List<PriceTier> tiers); 206 207 /** 208 * <p>Custom Fields defined for the Price.</p> 209 * @param custom value to be set 210 */ 211 212 public void setCustom(final CustomFields custom); 213 214 /** 215 * factory method 216 * @return instance of Price 217 */ 218 public static Price of() { 219 return new PriceImpl(); 220 } 221 222 /** 223 * factory method to create a shallow copy Price 224 * @param template instance to be copied 225 * @return copy instance 226 */ 227 public static Price of(final Price template) { 228 PriceImpl instance = new PriceImpl(); 229 instance.setId(template.getId()); 230 instance.setKey(template.getKey()); 231 instance.setValue(template.getValue()); 232 instance.setCountry(template.getCountry()); 233 instance.setCustomerGroup(template.getCustomerGroup()); 234 instance.setChannel(template.getChannel()); 235 instance.setValidFrom(template.getValidFrom()); 236 instance.setValidUntil(template.getValidUntil()); 237 instance.setDiscounted(template.getDiscounted()); 238 instance.setTiers(template.getTiers()); 239 instance.setCustom(template.getCustom()); 240 return instance; 241 } 242 243 /** 244 * factory method to create a deep copy of Price 245 * @param template instance to be copied 246 * @return copy instance 247 */ 248 @Nullable 249 public static Price deepCopy(@Nullable final Price template) { 250 if (template == null) { 251 return null; 252 } 253 PriceImpl instance = new PriceImpl(); 254 instance.setId(template.getId()); 255 instance.setKey(template.getKey()); 256 instance.setValue(com.commercetools.api.models.common.TypedMoney.deepCopy(template.getValue())); 257 instance.setCountry(template.getCountry()); 258 instance.setCustomerGroup( 259 com.commercetools.api.models.customer_group.CustomerGroupReference.deepCopy(template.getCustomerGroup())); 260 instance.setChannel(com.commercetools.api.models.channel.ChannelReference.deepCopy(template.getChannel())); 261 instance.setValidFrom(template.getValidFrom()); 262 instance.setValidUntil(template.getValidUntil()); 263 instance.setDiscounted(com.commercetools.api.models.common.DiscountedPrice.deepCopy(template.getDiscounted())); 264 instance.setTiers(Optional.ofNullable(template.getTiers()) 265 .map(t -> t.stream() 266 .map(com.commercetools.api.models.common.PriceTier::deepCopy) 267 .collect(Collectors.toList())) 268 .orElse(null)); 269 instance.setCustom(com.commercetools.api.models.type.CustomFields.deepCopy(template.getCustom())); 270 return instance; 271 } 272 273 /** 274 * builder factory method for Price 275 * @return builder 276 */ 277 public static PriceBuilder builder() { 278 return PriceBuilder.of(); 279 } 280 281 /** 282 * create builder for Price instance 283 * @param template instance with prefilled values for the builder 284 * @return builder 285 */ 286 public static PriceBuilder builder(final Price template) { 287 return PriceBuilder.of(template); 288 } 289 290 /** 291 * accessor map function 292 * @param <T> mapped type 293 * @param helper function to map the object 294 * @return mapped value 295 */ 296 default <T> T withPrice(Function<Price, T> helper) { 297 return helper.apply(this); 298 } 299 300 /** 301 * gives a TypeReference for usage with Jackson DataBind 302 * @return TypeReference 303 */ 304 public static com.fasterxml.jackson.core.type.TypeReference<Price> typeReference() { 305 return new com.fasterxml.jackson.core.type.TypeReference<Price>() { 306 @Override 307 public String toString() { 308 return "TypeReference<Price>"; 309 } 310 }; 311 } 312}