<%#
 Copyright 2013-2025 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 (databaseTypeCouchbase) { _%>
import org.springframework.data.couchbase.core.mapping.Field;
<%_ } _%>
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
<%_ if (databaseTypeSql && ormTool === 'mybatis') { _%>
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.FieldFill;
<%_ } else { _%>
  <%_ if (!reactive) { _%>
import org.springframework.data.annotation.CreatedBy;
  <%_ } _%>
import org.springframework.data.annotation.CreatedDate;
  <%_ if (!reactive) { _%>
import org.springframework.data.annotation.LastModifiedBy;
  <%_ } _%>
import org.springframework.data.annotation.LastModifiedDate;
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
import org.springframework.data.mongodb.core.mapping.Field;
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
import org.springframework.data.neo4j.core.schema.Property;
<%_ } _%>
<%_ if (databaseTypeSql && !reactive) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
  <%_ } _%>
<%_ } _%>

import java.io.Serializable;
import java.time.Instant;
<%_ if (databaseTypeSql) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
import jakarta.persistence.Column;
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeSql && !reactive) { _%>
  <%_ if (ormTool !== 'mybatis') { _%>
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
  <%_ } _%>
<%_ } _%>
<%_ if (userIdTypeName === 'UUID') { _%>
import java.util.UUID;
<%_ } _%>

/**
 * Base abstract class for entities which will hold definitions for created, last modified, created by,
 * last modified by attributes.
 */
<%_ if (databaseTypeSql && !reactive) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
  <%_ } _%>
<%_ } _%>
@JsonIgnoreProperties(value = { "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" }, allowGetters = true)
public abstract class AbstractAuditingEntity<T, E> implements Serializable {

    private static final long serialVersionUID = 1L;

    public abstract T getId();

<%_ if (!reactive) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
    @CreatedBy
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
    @Column(name = "created_by", nullable = false, length = 50, updatable = false)
  <%_ } else { _%>
    @TableField(value = "created_by", fill = FieldFill.INSERT)
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
    @Field("created_by")
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
    @Field
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
    @Property("created_by")
<%_ } _%>
    private <%= userIdTypeName %> createdBy;<%# modify by begcode %>

<%_ if (ormTool === 'hibernate') { _%>
    @CreatedDate
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
    @Column(name = "created_date", updatable = false)
  <%_ } else { _%>
    @TableField(value = "created_date", fill = FieldFill.INSERT)
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
    @Field("created_date")
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
    @Field
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
    @Property("created_date")
<%_ } _%>
    private Instant createdDate;

<%_ if (!reactive) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
    @LastModifiedBy
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
    @Column(name = "last_modified_by", length = 50)
  <%_ } else { _%>
    @TableField(value = "last_modified_by", fill = FieldFill.INSERT_UPDATE)
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
    @Field("last_modified_by")
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
    @Field
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
    @Property("last_modified_by")
<%_ } _%>
    private <%= userIdTypeName %> lastModifiedBy;<%# modify by begcode %>

<%_ if (ormTool === 'hibernate') { _%>
    @LastModifiedDate
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
  <%_ if (ormTool === 'hibernate') { _%>
    @Column(name = "last_modified_date")
  <%_ } else { _%>
    @TableField(value = "last_modified_date", fill = FieldFill.INSERT_UPDATE)
  <%_ } _%>
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
    @Field("last_modified_date")
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
    @Field
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
    @Property("last_modified_date")
<%_ } _%>
    private Instant lastModifiedDate;

    public <%= userIdTypeName %> getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(<%= userIdTypeName %> createdBy) {
        this.createdBy = createdBy;
    }

    public Instant getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Instant createdDate) {
        this.createdDate = createdDate;
    }

    public <%= userIdTypeName %> getLastModifiedBy() {
        return lastModifiedBy;
    }

    public void setLastModifiedBy(<%= userIdTypeName %> lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    public Instant getLastModifiedDate() {
        return lastModifiedDate;
    }

    public void setLastModifiedDate(Instant lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    public E createdBy(<%= userIdTypeName %> createdBy) {
        this.createdBy = createdBy;
        return (E) this;
    }

    public E lastModifiedBy(<%= userIdTypeName %> lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
        return (E) this;
    }

    public E lastModifiedDate(Instant lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
        return (E) this;
    }
    public E createdDate(Instant createdDate) {
        this.createdDate = createdDate;
        return (E) this;
    }
}
