<%#
 Copyright 2013-2021 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 <%= packageName %>.domain;

<%_ if (enableHibernateCache) { _%>
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
<%_ } _%>
<%_ if (databaseTypeMongodb || databaseTypeCouchbase) { _%>
import org.springframework.data.annotation.Id;
import org.springframework.data.<%= databaseType %>.core.mapping.Document;
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
  <%_ if (!reactive) { _%>
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
  <%_ } else { _%>
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Persistable;
import org.springframework.data.relational.core.mapping.Table;

  <%_ } _%>
<%_ } _%>
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Objects;

/**
 * An authority (a security role) used by Spring Security.
 */
<%_ if (databaseTypeSql && !reactive) { _%>
@Entity
@Table(name = "<%= jhiTablePrefix %>_authority")
  <%_ if (enableHibernateCache) { _%>
    <%_ if (cacheProviderInfinispan) { _%>
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    <%_ } else { _%>
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    <%_ } _%>
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeSql && reactive) { _%>
@Table("<%= jhiTablePrefix %>_authority")
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
@Document(collection = "<%= jhiTablePrefix %>_authority")
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
@Node("<%= jhiTablePrefix %>_authority")
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
@Document
<%_ } _%>
public class Authority implements Serializable<% if (databaseTypeSql && reactive) { %>, Persistable<String><% } %> {

    private static final long serialVersionUID = 1L;

    @NotNull
    @Size(max = 50)
    @Id
<%_ if (databaseTypeSql && !reactive) { _%>
    @Column(length = 50)
<%_ } _%>
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Authority)) {
            return false;
        }
        return Objects.equals(name, ((Authority) o).name);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(name);
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "Authority{" +
            "name='" + name + '\'' +
            "}";
    }
<%_ if (databaseTypeSql && reactive) { _%>

    @Override
    public String getId() {
        return name;
    }

    @Override
    public boolean isNew() {
        return true;
    }
<%_ } _%>
}
