package _VisualDVM.Passes.All;
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
import _VisualDVM.Global;
import _VisualDVM.Passes.Server.ComponentsServerPass;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.Utils;

import java.io.File;
public class SynchronizeCredentials extends ComponentsServerPass<Object> {
    File new_db_file;
    @Override
    public String getIconPath() {
        return "/icons/ComponentsActual.png";
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        return Global.mainModule.getAccount().role.equals(AccountRole.Admin) && SendRequest(ServerCode.ReceiveCredentialsDatabase);
    }
    @Override
    protected void showPreparation() throws Exception {
        getServer().credentials_db.DropUI();
    }
    @Override
    protected void body() throws Exception {
        request.server_response.Unpack(new_db_file = Utils.getTempFileName("сdb"));
    }
    @Override
    protected void performDone() throws Exception {
        getServer().credentials_db.ReplaceFileAndReconnect(new_db_file);
    }
    @Override
    protected void showDone() throws Exception {
        if (Global.mainModule.getUI().hasMainWindow())
            getServer().credentials_db.ResetUI();
    }
}
