001
002package com.commercetools.api.models.cart_discount;
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>Describes how the Cart Discount interacts with other Discounts.</p>
015 */
016@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
017public interface StackingMode extends JsonEnum {
018
019    /**
020        <p>Applies other matching Discounts after applying this one.</p>
021
022    */
023    StackingMode STACKING = StackingModeEnum.STACKING;
024    /**
025        <p>Doesn't apply any more matching Discounts after this one if it's successfully applied.</p>
026
027    */
028    StackingMode STOP_AFTER_THIS_DISCOUNT = StackingModeEnum.STOP_AFTER_THIS_DISCOUNT;
029
030    /**
031     * possible values of StackingMode
032     */
033    enum StackingModeEnum implements StackingMode {
034        /**
035         * Stacking
036         */
037        STACKING("Stacking"),
038
039        /**
040         * StopAfterThisDiscount
041         */
042        STOP_AFTER_THIS_DISCOUNT("StopAfterThisDiscount");
043        private final String jsonName;
044
045        private StackingModeEnum(final String jsonName) {
046            this.jsonName = jsonName;
047        }
048
049        public String getJsonName() {
050            return jsonName;
051        }
052
053        public String toString() {
054            return jsonName;
055        }
056    }
057
058    /**
059     * the JSON value
060     * @return json value
061     */
062    @JsonValue
063    String getJsonName();
064
065    /**
066     * the enum value
067     * @return name
068     */
069    String name();
070
071    /**
072     * convert value to string
073     * @return string representation
074     */
075    String toString();
076
077    /**
078     * factory method for a enum value of StackingMode
079     * if no enum has been found an anonymous instance will be created
080     * @param value the enum value to be wrapped
081     * @return enum instance
082     */
083    @JsonCreator
084    public static StackingMode findEnum(String value) {
085        return findEnumViaJsonName(value).orElse(new StackingMode() {
086            @Override
087            public String getJsonName() {
088                return value;
089            }
090
091            @Override
092            public String name() {
093                return value.toUpperCase();
094            }
095
096            public String toString() {
097                return value;
098            }
099        });
100    }
101
102    /**
103     * method to find enum using the JSON value
104     * @param jsonName the json value to be wrapped
105     * @return optional of enum instance
106     */
107    public static Optional<StackingMode> findEnumViaJsonName(String jsonName) {
108        return Arrays.stream(values()).filter(t -> t.getJsonName().equals(jsonName)).findFirst();
109    }
110
111    /**
112     * possible enum values
113     * @return array of possible enum values
114     */
115    public static StackingMode[] values() {
116        return StackingModeEnum.values();
117    }
118
119}