001 002package com.commercetools.api.models.cart; 003 004import java.util.Arrays; 005import java.util.Optional; 006 007import com.fasterxml.jackson.annotation.JsonCreator; 008import com.fasterxml.jackson.annotation.JsonValue; 009 010import io.vrap.rmf.base.client.JsonEnum; 011import io.vrap.rmf.base.client.utils.Generated; 012 013/** 014 * <p>Indicates how a Line Item is added to a Cart.</p> 015 */ 016@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 017public interface LineItemMode extends JsonEnum { 018 019 /** 020 <p>The Line Item is added during <a href="/../api/projects/carts#create-cart">Cart creation</a> or using the <a href="ctp:api:type:CartAddLineItemAction">Add LineItem</a> update action. 021 The Line Item quantity can be changed without restriction.</p> 022 023 */ 024 LineItemMode STANDARD = LineItemModeEnum.STANDARD; 025 /** 026 <p>The Line Item is added automatically by a Cart Discount with <a href="ctp:api:type:CartDiscountValueGiftLineItem">CartDiscountValueGiftLineItem</a>.</p> 027 <p>The quantity cannot be <a href="ctp:api:type:CartChangeLineItemQuantityAction">increased</a>, and it won't be merged when the same Line Item is <a href="ctp:api:type:CartAddLineItemAction">added</a> to the Cart. 028 If the gift is <a href="ctp:api:type:CartRemoveLineItemAction">removed</a>, an entry is added to the <code>refusedGifts</code> array and the discount won't be applied to the Cart. 029 The price cannot be changed <a href="ctp:api:type:CartSetLineItemTotalPriceAction">externally</a>.</p> 030 <p>All other updates, such as the ones related to Custom Fields, can be used.</p> 031 032 */ 033 LineItemMode GIFT_LINE_ITEM = LineItemModeEnum.GIFT_LINE_ITEM; 034 035 /** 036 * possible values of LineItemMode 037 */ 038 enum LineItemModeEnum implements LineItemMode { 039 /** 040 * Standard 041 */ 042 STANDARD("Standard"), 043 044 /** 045 * GiftLineItem 046 */ 047 GIFT_LINE_ITEM("GiftLineItem"); 048 private final String jsonName; 049 050 private LineItemModeEnum(final String jsonName) { 051 this.jsonName = jsonName; 052 } 053 054 public String getJsonName() { 055 return jsonName; 056 } 057 058 public String toString() { 059 return jsonName; 060 } 061 } 062 063 /** 064 * the JSON value 065 * @return json value 066 */ 067 @JsonValue 068 String getJsonName(); 069 070 /** 071 * the enum value 072 * @return name 073 */ 074 String name(); 075 076 /** 077 * convert value to string 078 * @return string representation 079 */ 080 String toString(); 081 082 /** 083 * factory method for a enum value of LineItemMode 084 * if no enum has been found an anonymous instance will be created 085 * @param value the enum value to be wrapped 086 * @return enum instance 087 */ 088 @JsonCreator 089 public static LineItemMode findEnum(String value) { 090 return findEnumViaJsonName(value).orElse(new LineItemMode() { 091 @Override 092 public String getJsonName() { 093 return value; 094 } 095 096 @Override 097 public String name() { 098 return value.toUpperCase(); 099 } 100 101 public String toString() { 102 return value; 103 } 104 }); 105 } 106 107 /** 108 * method to find enum using the JSON value 109 * @param jsonName the json value to be wrapped 110 * @return optional of enum instance 111 */ 112 public static Optional<LineItemMode> findEnumViaJsonName(String jsonName) { 113 return Arrays.stream(values()).filter(t -> t.getJsonName().equals(jsonName)).findFirst(); 114 } 115 116 /** 117 * possible enum values 118 * @return array of possible enum values 119 */ 120 public static LineItemMode[] values() { 121 return LineItemModeEnum.values(); 122 } 123 124}