package Common.Database.Objects;
import Common.Utils.Index;
import Common.Utils.Utils_;
import Common.Visual.Selectable;
import com.sun.org.glassfish.gmbal.Description;

import java.io.Serializable;
import java.util.Objects;
public abstract class DBObject implements Selectable, Serializable {
    //<editor-fold desc="Selectable">
    @Description("IGNORE")
    private boolean selected = false;
    //------
    public DBObject() {
    }
    public DBObject(DBObject src) {
        this.SynchronizeFields(src);
    }
    @Override
    public boolean isSelected() {
        return selected;
    }
    @Override
    public void select(boolean flag) {
        if (selected != flag) {
            selected = flag;
            Index counter = getSelectionCounter();
            if (Objects.nonNull(counter)) {
                if (selected) counter.Inc();
                else counter.Dec();
            }
        }
    }
    //</editor-fold>
    public Index getSelectionCounter() {
        return null;
    }
    public abstract Object getPK();
    public String getBDialogName() {
        return Utils_.Brackets(getDialogName());
    }
    public String getDialogName() {
        return getPK().toString();
    }
    public String getFKName() {
        return getClass().getSimpleName().toLowerCase() + "_id";
    }
    public Object getEmptyFK() {
        return null;
    }
    @Override
    public String toString() {
        return getBDialogName();
    }
    //---
    public void SynchronizeFields(DBObject src) {
        selected = src.selected;
    }
}
