package _VisualDVM.Passes.Server;
import Common.Database.Objects.riDBObject;
import Common.Utils.Pair;
import _VisualDVM.Global;
import _VisualDVM.Repository.Server.RepositoryServer;
import _VisualDVM.Repository.Server.SafeServerExchangeUnit;
import _VisualDVM.Repository.Server.ServerCode;
public abstract class CloneServerObject<S extends RepositoryServer, D extends riDBObject> extends PublishServerObject<S, D> {
    public D src;
    public CloneServerObject(S server_in, Class<D> d_in) {
        super(server_in, d_in);
    }
    @Override
    public String getIconPath() {
        return "/icons/MultiFiles.png";
    }
    @Override
    public String getDescription_() {
        return "дублирование";
    }
    protected abstract Class currentClass();
    @Override
    protected boolean canStart(Object... args) throws Exception {
        src = null;
        if (!server.db.getTable(currentClass()).getUI().CheckCurrent(Log))
            return false;
        //---------
        pk = null;
        src = (D) server.db.getTable(currentClass()).getUI().getCurrent();
        return true;
    }
    @Override
    protected void ServerAction() throws Exception {
        Command(new SafeServerExchangeUnit(ServerCode.CloneObjectByPK,
                Global.mainModule.getAccount().name + "\n" + Global.mainModule.getAccount().email,
                new Pair<>(src.getClass(), src.getPK())));
        pk = server_response.object;
    }
}
