package com.face.global.entity;


import com.face.global.enums.DeleteType;
import lombok.Data;

import java.util.Date;
@Data
public class BaseEntity {

    private Date createDate;

    private String createUser;

    private String createUserType;

    private String modifyUser;

    private Date modifyDate;

    private String modifyUserType;

    private String isDelete;

    public boolean checkDelete() {
        return DeleteType.DELETE.getCode().equals(isDelete);
    }



    public void recoverForModify(BaseEntity dbBaseEntity) {
        this.setCreateUser(dbBaseEntity.getCreateUser());
        this.setCreateDate(dbBaseEntity.getCreateDate());
        this.setCreateUserType(dbBaseEntity.getCreateUserType());
        this.setIsDelete(dbBaseEntity.getIsDelete());
    }


    public void init(String user, String userType) {
        this.initCreate(user,userType);
        this.initModify(user,userType);
        this.initDelete();
    }

    public void initCreate(String createUser, String createUserType) {
        this.setCreateDate(new Date());
        this.setCreateUser(createUser);
        this.setCreateUserType(createUserType);
    }

    public void initModify(String modifyUser, String modifyUserType) {
        this.setModifyDate(new Date());
        this.setModifyUser(modifyUser);
        this.setModifyUserType(modifyUserType);
    }

    public void initDelete() {
        this.setIsDelete(DeleteType.NO_DELETE.getCode());
    }
}
