package com.hdkj.lt.base.model.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;

import javax.validation.groups.Default;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @Description: 超类基础实体
 * @Author: wenhao
 * @Create: 2022/05/15 10:08
 * @Version: 1.0
 */
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString
@EqualsAndHashCode
public class SuperEntity /*, Cloneable*/ {

    private static final long serialVersionUID = -2945108025807370046L;

    public static final String CREATE_BY = "createBy";

    public static final String CREATE_TIME = "createTime";

    public static final String IS_DELETE = "isDelete";

    @ApiModelProperty(value = "创建人ID")
    @TableField(value = "CREATE_BY", fill = FieldFill.INSERT)
    protected Long createBy;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
    protected LocalDateTime createTime;

    @ApiModelProperty(value = "是否删除")
    @TableField(value = "IS_DELETE", fill = FieldFill.INSERT)
    protected String isDelete;

    public String getTableName() {
        TableName tableNameAnno = this.getClass().getDeclaredAnnotation(TableName.class);
        if (Objects.nonNull(tableNameAnno)) {
            return tableNameAnno.value();
        }
        return StringUtils.EMPTY;
    }

    /*@Override
    public Object clone() {
        // 支持克隆，提高性能，仅仅是浅克隆
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            ExceptionCast.cast("clone failed");
        }
        return null;
    }*/

    /**
     * 保存和缺省验证组
     */
    public interface Save extends Default {

    }

    /**
     * 更新和缺省验证组
     */
    public interface Update extends Default {

    }

}
