package <%=packageName%>.domain;

<%_ if (databaseTypeSql) { _%>
import javax.persistence.*;
import org.hibernate.annotations.Any;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
    <%_ if (ormTool === 'hibernate') { _%>
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
        <%_ if (softDelete) { _%>
import java.time.LocalDate;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
        <%_ } _%>
    <%_ } else { _%>
import com.baomidou.mybatisplus.annotation.*;
    <%_ } _%>
<%_ } _%>
import <%= javaVersion === '17' ? 'jakarta' : 'javax'%>.validation.constraints.*;
<%_ if (databaseTypeMongodb) { _%>
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.DBRef;
<%_ } _%>

import java.io.Serializable;

/**
 * 通用扩展数据
 */
<%_ if (databaseTypeSql) { _%>
    <%_ if (ormTool === 'hibernate') { _%>
@Entity
@Table(name = "common_ext_data")
@DynamicUpdate
    <%_ } else { _%>
@TableName(value = "common_ext_data")
        <%_ if (user.primaryKey.fields[0].jpaGeneratedValue === 'sequence') { _%>
@KeySequence("sequence_generator")
        <%_ } _%>
    <%_ } _%>
<%_ } _%>
    <%_ if (databaseTypeMongodb) { _%>
@Document(collection = "common_ext_data")
    <%_ } else if (databaseTypeNeo4j) { _%>
@Node
    <%_ } else if (databaseTypeCouchbase) { _%>
@Document
    <%_ } else if (databaseTypeCassandra) { _%>
@Table("CommonExtData")
    <%_ } _%>
<%_ if (searchEngine === 'elasticsearch') { _%>
@org.springframework.data.elasticsearch.annotations.Document(indexName = "commonextdata")
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
<%_ } _%>
public class CommonExtData implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    <%_ if (databaseTypeSql) { _%>
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    <%_ } _%>
    private <%= databaseTypeSql ? 'Long' : 'String'%> id;

    /**
     * 属性名
     */
    @NotNull
    @Size(max = 100)
    <%_ if (databaseTypeSql) { _%>
    @Column(name = "field_name", length = 100, nullable = false)
    <%_ } _%>
    private String fieldName;

    /**
     * 通用字段类型
     */
    <%_ if (databaseTypeSql) { _%>
    @Column(name = "common_field_type", insertable = false, updatable = false)
    <%_ } _%>
    private String commonFieldType;

    /**
     * 通用数据Id
     */
    <%_ if (databaseTypeSql) { _%>
    @Column(name = "common_field_id", insertable = false, updatable = false)
    <%_ } _%>
    private Long commonFieldId;

    /**
     * 宿主实体名称
     */
    <%_ if (databaseTypeSql) { _%>
    @Column(name = "owner_type", insertable = false, updatable = false)
    <%_ } _%>
    private String ownerType;

    /**
     * 宿主实体Id
     */
    <%_ if (databaseTypeSql) { _%>
    @Column(name = "owner_id", insertable = false, updatable = false)
    <%_ } _%>
    private Long ownerId;
    <%_ if (softDelete && databaseTypeSql) { _%>

    @Column(name = "del_flag")
    private Boolean delFlag;
    <%_ } _%>

    <%_ if (databaseTypeSql) { _%>
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @Cascade({org.hibernate.annotations.CascadeType.ALL})
    @Any(metaDef = "ExtDataMetaDef",metaColumn = @Column(name = "common_field_type"), fetch = FetchType.EAGER)
    @JoinColumn(name = "common_field_id")
    <%_ } _%>
    private CommonField value;

    <%_ if (databaseTypeSql) { _%>
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @Cascade({org.hibernate.annotations.CascadeType.ALL})
    @Any(metaDef = "OwnerMetaDef",metaColumn = @Column(name = "owner_type"), fetch = FetchType.EAGER)
    @JoinColumn(name = "owner_id")
    <%_ } _%>
    private Owner owner;

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public <%= databaseTypeSql ? 'Long' : 'String'%> getId() {
        return id;
    }

    public void setId(<%= databaseTypeSql ? 'Long' : 'String'%> id) {
        this.id = id;
    }

    public String getFieldName() {
        return fieldName;
    }

    public CommonExtData fieldName(String fieldName) {
        this.fieldName = fieldName;
        return this;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getCommonFieldType() {
        return commonFieldType;
    }

    public CommonExtData commonFieldType(String commonFieldType) {
        this.commonFieldType = commonFieldType;
        return this;
    }

    public void setCommonFieldType(String commonFieldType) {
        this.commonFieldType = commonFieldType;
    }

    public Long getCommonFieldId() {
        return commonFieldId;
    }

    public CommonExtData commonFieldId(Long commonFieldId) {
        this.commonFieldId = commonFieldId;
        return this;
    }

    public void setCommonFieldId(Long commonFieldId) {
        this.commonFieldId = commonFieldId;
    }

    public String getOwnerType() {
        return ownerType;
    }

    public CommonExtData ownerType(String ownerType) {
        this.ownerType = ownerType;
        return this;
    }

    public void setOwnerType(String ownerType) {
        this.ownerType = ownerType;
    }

    public Long getOwnerId() {
        return ownerId;
    }

    public CommonExtData ownerId(Long ownerId) {
        this.ownerId = ownerId;
        return this;
    }

    public void setOwnerId(Long ownerId) {
        this.ownerId = ownerId;
    }
    <%_ if (softDelete && databaseTypeSql) { _%>

    public Boolean getDelFlag() {
        return delFlag;
    }

    public CommonExtData delFlag(Boolean delFlag) {
        this.delFlag = delFlag;
        return this;
    }

    public void setDelFlag(Boolean delFlag) {
        this.delFlag = delFlag;
    }
<%_ } _%>

    public CommonField getValue() {
        return value;
    }

    public void setValue(CommonField value) {
        this.value = value;
    }

    public Owner getOwner() {
        return owner;
    }

    public void setOwner(Owner owner) {
        this.owner = owner;
    }

    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof CommonExtData)) {
            return false;
        }
        return id != null && id.equals(((CommonExtData) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "CommonExtData{" +
            "id=" + getId() +
            ", fieldName='" + getFieldName() + "'" +
            ", commonFieldType='" + getCommonFieldType() + "'" +
            ", commonFieldId=" + getCommonFieldId() +
            ", ownerType='" + getOwnerType() + "'" +
            ", ownerId=" + getOwnerId() +
            <%_ if (softDelete && databaseTypeSql) { _%>
            ", delFlag='" + getDelFlag() + "'" +
            <%_ } _%>
            "}";
    }
}
