package cn.lihongjie.coal.base.entity;

import jakarta.persistence.MappedSuperclass;

import lombok.Getter;
import lombok.Setter;

import org.hibernate.annotations.Comment;

import java.util.Objects;

@MappedSuperclass
@Getter
@Setter
public class CommonEntity extends BaseEntity {

    @Comment("名称")
    private String name;

    @Comment("编码")
    private String code;

    @Comment("备注")
    private String remarks;

    @Comment("排序键")
    private Integer sortKey;

    @Comment("常用状态 0 禁用 1 启用")
    private Integer status;

    public boolean isDisabled() {
        return Objects.equals(status, 0);
    }

    @Override
    public void prePersist() {
        this.status = this.status == null ? 1 : this.status;
        super.prePersist();
    }

    @Override
    public void preUpdate() {
        this.status = this.status == null ? 1 : this.status;
        super.preUpdate();
    }
}
