001
002package com.commercetools.api.models.extension;
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>An Extension gets called during any of the following requests of an API call, but before the result is persisted.</p>
015 */
016@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
017public interface ExtensionAction extends JsonEnum {
018
019    /**
020        <p>An Extension gets called during a Create request.</p>
021
022    */
023    ExtensionAction CREATE = ExtensionActionEnum.CREATE;
024    /**
025        <p>An Extension gets called during an Update request.</p>
026
027    */
028    ExtensionAction UPDATE = ExtensionActionEnum.UPDATE;
029
030    /**
031     * possible values of ExtensionAction
032     */
033    enum ExtensionActionEnum implements ExtensionAction {
034        /**
035         * Create
036         */
037        CREATE("Create"),
038
039        /**
040         * Update
041         */
042        UPDATE("Update");
043        private final String jsonName;
044
045        private ExtensionActionEnum(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 ExtensionAction
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 ExtensionAction findEnum(String value) {
085        return findEnumViaJsonName(value).orElse(new ExtensionAction() {
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<ExtensionAction> 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 ExtensionAction[] values() {
116        return ExtensionActionEnum.values();
117    }
118
119}