// Path: src/main/java/com/jblur/acme_client/command/ACMECommand.java
// public abstract class ACMECommand implements Command {
//     private static final Logger LOG = LoggerFactory.getLogger(ACMECommand.class);
//     public boolean error = false;
//     protected JsonObject result = new JsonObject();
//     private Parameters parameters;
//     private Session session;
//     private Gson gson = new Gson();
// 
//     public ACMECommand(Parameters parameters) {
//         this.parameters = parameters;
//         this.session = new Session(this.parameters.getAcmeServerUrl());
//     }
// 
//     public Parameters getParameters() {
//         return this.parameters;
//     }
// 
//     protected Session getSession() {
//         return this.session;
//     }
// 
//     public Gson getGson() {
//         return this.gson;
//     }
// 
//     public String getResult() {
//         return gson.toJson(result);
//     }
// 
//     private void preExecution() {
//         error = false;
//         result = new JsonObject();
//     }
// 
//     @Override
//     public void execute() {
//         preExecution();
//         commandExecution();
//         postExecution();
//     }
// 
//     private void postExecution() {
//         result.add("status", getGson().toJsonTree((error) ? "error" : "ok"));
//     }
// 
//     public abstract void commandExecution();
// 
// }
// 
// Path: src/main/java/com/jblur/acme_client/command/AccountKeyNotFoundException.java
// public class AccountKeyNotFoundException extends Exception {
// 
//     public AccountKeyNotFoundException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: src/main/java/com/jblur/acme_client/manager/AccountManager.java
// public class AccountManager {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(Application.class);
// 
//     private Account account;
//     private Login login;
// 
//     public AccountManager(Login login) {
//         this.account = login.getAccount();
//         this.login = login;
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, boolean agreeToTermsOfService)
//             throws AcmeException {
//         AccountBuilder accountBuilder = new AccountBuilder().useKeyPair(keyPair);
//         if(agreeToTermsOfService){
//             accountBuilder = accountBuilder.agreeToTermsOfService();
//         }
//         this.login = accountBuilder.createLogin(session);
//         this.account = this.login.getAccount();
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, String keyIdentifier,
//                           SecretKey macKey, boolean agreeToTermsOfService)
//             throws AcmeException {
//         AccountBuilder accountBuilder = new AccountBuilder()
//                 .withKeyIdentifier(keyIdentifier, macKey).useKeyPair(keyPair);
//         if(agreeToTermsOfService){
//             accountBuilder = accountBuilder.agreeToTermsOfService();
//         }
//         this.login = accountBuilder.createLogin(session);
//         this.account = this.login.getAccount();
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, String keyIdentifier,
//                           String macKey, boolean agreeToTermsOfService)
//             throws AcmeException {
//         AccountBuilder accountBuilder = new AccountBuilder()
//                 .withKeyIdentifier(keyIdentifier, macKey).useKeyPair(keyPair);
//         if(agreeToTermsOfService){
//             accountBuilder = accountBuilder.agreeToTermsOfService();
//         }
//         this.login = accountBuilder.createLogin(session);
//         this.account = this.login.getAccount();
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, URL accountLocationUrl) {
//         this.login = session.login(accountLocationUrl, keyPair);
//         this.account = this.login.getAccount();
//     }
// 
//     public Account getAccount() {
//         return this.account;
//     }
// 
//     public Login getLogin(){
//         return this.login;
//     }
// 
//     public void addContact(URI contactURI) throws AcmeException {
//         this.account.modify()
//                 .addContact(contactURI)
//                 .commit();
//     }
// 
//     public void changeAccountKeyPair(KeyPair keyPair) throws AcmeException {
//         this.account.changeKey(keyPair);
//     }
// 
//     public void deactivateAccount() throws AcmeException {
//         try {
//             this.account.deactivate();
//         } catch (AcmeException e) {
//             if (!e.getMessage().equals("HTTP 202: Accepted")) {
//                 throw e;
//             }
//         }
//     }
// 
// }


import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.jblur.acme_client.command.ACMECommand;
import com.jblur.acme_client.command.AccountKeyNotFoundException;
import com.jblur.acme_client.command.certificate.*;
import com.jblur.acme_client.command.registration.*;
import com.jblur.acme_client.manager.AccountManager;
import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeUserActionRequiredException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
            LOG.error("Manual action required. Please visit url with instructions: "+e.getInstance().toString(), e);
            if(e.getTermsOfServiceUri()!=null){
                LOG.error("You should agree to terms of service: "+e.getTermsOfServiceUri());
            }
            result=RESULT_ERROR;
        } catch (AcmeException e) {
            e.printStackTrace();
            result=RESULT_ERROR;
        }

        System.out.println(result);
    }

    private AccountManager getAccountManager() {
        AccountManager accountManager = null;
        try {
            RegistrationCommand registrationCommand = new RegistrationCommand(parameters);
            result = executeACMECommand(registrationCommand);
            accountManager = registrationCommand.getAccountManager();
            if (accountManager == null) {
                LOG.error("Cannot get account information.");
            }
        } catch (AccountKeyNotFoundException e) {
            LOG.error("Account key not found.", e);
        } catch (AcmeException e) {
            LOG.error("Cannot be authorized.", e);
        }
        return accountManager;
    }

// Path: src/main/java/com/jblur/acme_client/command/ACMECommand.java
// public abstract class ACMECommand implements Command {
//     private static final Logger LOG = LoggerFactory.getLogger(ACMECommand.class);
//     public boolean error = false;
//     protected JsonObject result = new JsonObject();
//     private Parameters parameters;
//     private Session session;
//     private Gson gson = new Gson();
// 
//     public ACMECommand(Parameters parameters) {
//         this.parameters = parameters;
//         this.session = new Session(this.parameters.getAcmeServerUrl());
//     }
// 
//     public Parameters getParameters() {
//         return this.parameters;
//     }
// 
//     protected Session getSession() {
//         return this.session;
//     }
// 
//     public Gson getGson() {
//         return this.gson;
//     }
// 
//     public String getResult() {
//         return gson.toJson(result);
//     }
// 
//     private void preExecution() {
//         error = false;
//         result = new JsonObject();
//     }
// 
//     @Override
//     public void execute() {
//         preExecution();
//         commandExecution();
//         postExecution();
//     }
// 
//     private void postExecution() {
//         result.add("status", getGson().toJsonTree((error) ? "error" : "ok"));
//     }
// 
//     public abstract void commandExecution();
// 
// }
// 
// Path: src/main/java/com/jblur/acme_client/command/AccountKeyNotFoundException.java
// public class AccountKeyNotFoundException extends Exception {
// 
//     public AccountKeyNotFoundException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: src/main/java/com/jblur/acme_client/manager/AccountManager.java
// public class AccountManager {
// 
//     private static final Logger LOG = LoggerFactory.getLogger(Application.class);
// 
//     private Account account;
//     private Login login;
// 
//     public AccountManager(Login login) {
//         this.account = login.getAccount();
//         this.login = login;
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, boolean agreeToTermsOfService)
//             throws AcmeException {
//         AccountBuilder accountBuilder = new AccountBuilder().useKeyPair(keyPair);
//         if(agreeToTermsOfService){
//             accountBuilder = accountBuilder.agreeToTermsOfService();
//         }
//         this.login = accountBuilder.createLogin(session);
//         this.account = this.login.getAccount();
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, String keyIdentifier,
//                           SecretKey macKey, boolean agreeToTermsOfService)
//             throws AcmeException {
//         AccountBuilder accountBuilder = new AccountBuilder()
//                 .withKeyIdentifier(keyIdentifier, macKey).useKeyPair(keyPair);
//         if(agreeToTermsOfService){
//             accountBuilder = accountBuilder.agreeToTermsOfService();
//         }
//         this.login = accountBuilder.createLogin(session);
//         this.account = this.login.getAccount();
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, String keyIdentifier,
//                           String macKey, boolean agreeToTermsOfService)
//             throws AcmeException {
//         AccountBuilder accountBuilder = new AccountBuilder()
//                 .withKeyIdentifier(keyIdentifier, macKey).useKeyPair(keyPair);
//         if(agreeToTermsOfService){
//             accountBuilder = accountBuilder.agreeToTermsOfService();
//         }
//         this.login = accountBuilder.createLogin(session);
//         this.account = this.login.getAccount();
//     }
// 
//     public AccountManager(KeyPair keyPair, Session session, URL accountLocationUrl) {
//         this.login = session.login(accountLocationUrl, keyPair);
//         this.account = this.login.getAccount();
//     }
// 
//     public Account getAccount() {
//         return this.account;
//     }
// 
//     public Login getLogin(){
//         return this.login;
//     }
// 
//     public void addContact(URI contactURI) throws AcmeException {
//         this.account.modify()
//                 .addContact(contactURI)
//                 .commit();
//     }
// 
//     public void changeAccountKeyPair(KeyPair keyPair) throws AcmeException {
//         this.account.changeKey(keyPair);
//     }
// 
//     public void deactivateAccount() throws AcmeException {
//         try {
//             this.account.deactivate();
//         } catch (AcmeException e) {
//             if (!e.getMessage().equals("HTTP 202: Accepted")) {
//                 throw e;
//             }
//         }
//     }
// 
// }


// Path: src/main/java/com/jblur/acme_client/CommandExecutor.java
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.jblur.acme_client.command.ACMECommand;
import com.jblur.acme_client.command.AccountKeyNotFoundException;
import com.jblur.acme_client.command.certificate.*;
import com.jblur.acme_client.command.registration.*;
import com.jblur.acme_client.manager.AccountManager;
import org.shredzone.acme4j.exception.AcmeException;
import org.shredzone.acme4j.exception.AcmeUserActionRequiredException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

            LOG.error("Manual action required. Please visit url with instructions: "+e.getInstance().toString(), e);
            if(e.getTermsOfServiceUri()!=null){
                LOG.error("You should agree to terms of service: "+e.getTermsOfServiceUri());
            }
            result=RESULT_ERROR;
        } catch (AcmeException e) {
            e.printStackTrace();
            result=RESULT_ERROR;
        }

        System.out.println(result);
    }

    private AccountManager getAccountManager() {
        AccountManager accountManager = null;
        try {
            RegistrationCommand registrationCommand = new RegistrationCommand(parameters);
            result = executeACMECommand(registrationCommand);
            accountManager = registrationCommand.getAccountManager();
            if (accountManager == null) {
                LOG.error("Cannot get account information.");
            }
        } catch (AccountKeyNotFoundException e) {
            LOG.error("Account key not found.", e);
        } catch (AcmeException e) {
            LOG.error("Cannot be authorized.", e);
        }
        return accountManager;
    }

    private String executeACMECommand(ACMECommand acmeCommand) {