<%#
 Copyright 2013-2023 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%= entityAbsolutePackage %>.domain.enumeration;

<%_ if (ormTool === 'mybatis') { _%>
import com.baomidou.mybatisplus.annotation.EnumValue;
<%_ } _%>
import com.fasterxml.jackson.annotation.JsonValue;

<%_ if (typeof javadoc === 'undefined') { _%>
/**
 * The <%= enumName %> enumeration.
 */
<%_ } else { _%>
<%= javadoc %>
<%_ } _%>
public enum <%= enumName %> {
<%_ if (withoutCustomValues && false) { _%><%# modify by begcode %>
<%= enumValues.map(enumValue => `${enumValue.comment && `\n${enumValue.comment}\n` || ''}    ${enumValue.name}`).join(', ') %>
<%_ } else {
  // The following code redefines the variable state to be 'without CustomValue' when name equals value.
  withoutCustomValues = enumValues.every(({name, value}) => name === value);
  withCustomValues = enumValues.every(({name, value}) => name !== value);
  withSomeCustomValues = !withoutCustomValues && !withCustomValues;

  enumValues.forEach((enumWithCustomValue, index) => {
    if (enumWithCustomValue.comment) {  _%>
    <%= enumWithCustomValue.comment %>
  <%_ }
  if (enumWithCustomValue.name === enumWithCustomValue.value) { _%>
    <%= enumWithCustomValue.name %>("<%= enumWithCustomValue.name %>", "<%= enumWithCustomValue.commentValue || enumWithCustomValue.value %>")<% if (index < enumValues.length - 1) { %>,<% } else { %>;<% } %>
  <%_ } else { _%>
    <%= enumWithCustomValue.name %>("<%= enumWithCustomValue.name %>", "<%= enumWithCustomValue.commentValue || enumWithCustomValue.value %>")<% if (index < enumValues.length - 1) { %>,<% } else { %>;<% } %>
    <%_ }
  }); _%>
    <%_ if (ormTool === 'mybatis') { _%>
    @EnumValue
    <%_ } _%>
    @JsonValue
  <%_ if (!withoutCustomValues || true) { _%><%# modify by begcode %>
    private<% if (withCustomValues) { %> final<% } %> String value;
    private<% if (withCustomValues) { %> final<% } %> String desc;<%# add by begcode %>

    <%_ if (withSomeCustomValues) { _%>
    <%= enumName %>() {}
    <%_ } _%>

    <%= enumName %>(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static <%= enumName %> getByValue(String value) {
        for (<%= enumName %> enum<%= enumName %> : <%= enumName %>.values()) {
            if (enum<%= enumName %>.getValue().equals(value)) {
                return enum<%= enumName %>;
            }
        }
        return null;
    }

    public static <%= enumName %> getByDesc(String desc) {
        for (<%= enumName %> enum<%= enumName %> : <%= enumName %>.values()) {
            if (enum<%= enumName %>.getDesc().equals(desc)) {
                return enum<%= enumName %>;
            }
        }
        return null;
    }

  <%_ } _%>
<%_ } _%>
}
