class EnvironmentHealerStepDefinitions {

    @Then("^recover$")
    public void recover() {
        boolean isSSM = !executionStateCache.getSsmCommandInvocationInstances().isEmpty();

        if (executionStateCache.isHealProcess()) {
            List<String> processes = executionStateCache.getProcessNames();
            for (String process : processes) {
                if (isSSM) {

                    healGivenSSMInstancesByProcess(process, executionStateCache.getSsmCommandInvocationInstances());
                } else {
                    healGivenInstancesByProcess(process, executionStateCache.getUnhealthyInstances());
                }
            }
        }

        if (executionStateCache.isHealNetwork()) {

            if (isSSM) {
                healSSMGivenInstancesFixingNetworkIssues(executionStateCache.getSsmCommandInvocationInstances());
            }
            else {
                healGivenInstancesFixingNetworkIssues(executionStateCache.getUnhealthyInstances());
            }
        }

        if (!executionStateCache.getBlockedDomains().isEmpty()) {
            if (isSSM) {

                executionStateCache.getBlockedDomains().parallelStream()
                        .forEach(domain -> healSSMGivenInstancesByDomainName(domain, executionStateCache.getSsmCommandInvocationInstances()));
            } else {
                executionStateCache.getBlockedDomains().parallelStream()
                        .forEach(domain -> healGivenInstancesByDomainName(domain, executionStateCache.getUnhealthyInstances()));
            }
        }

        if (executionStateCache.isCpuSpiked()) {
            if (isSSM) {

                healSSMGivenInstancesByFixingCPU(executionStateCache.getSsmCommandInvocationInstances());
            } else {
                healGivenInstancesByFixingCPU(executionStateCache.getUnhealthyInstances());
            }
        }

        if (executionStateCache.isBlockPort()) {
            List<Integer> portNums = executionStateCache.getPortNums();
            for (Integer port : portNums) {
                if (isSSM) {

                    healSSMGivenInstancesByFixingPort(port, executionStateCache.getSsmCommandInvocationInstances());
                } else {
                    healGivenInstancesByFixingPort(executionStateCache.getUnhealthyInstances());
                }
            }
        }

        if (executionStateCache.isRamDiskFull()) {
            if (isSSM) {
                healSSMGivenInstancesByFixingRamDisk(executionStateCache.getSsmCommandInvocationInstances());
            } else {
                healGivenInstancesByFixingRamDisk(executionStateCache.getUnhealthyInstances());
            }
        }


        if (executionStateCache.isBlockDynamoDB())
        {
            if (isSSM) {

                healSSMGivenInstancesByUnblockingDynamoDB(executionStateCache.getSsmCommandInvocationInstances());
            }
            else
            {
                healGivenInstancesByUnblockingDynamoDB(executionStateCache.getUnhealthyInstances());

            }
        }

        if (executionStateCache.isBlockS3())
        {
            if (isSSM) {

                healSSMGivenInstancesByUnblockingS3(executionStateCache.getSsmCommandInvocationInstances());
            }
            else
            {
                healGivenInstancesByUnblockingS3(executionStateCache.getUnhealthyInstances());

            }
        }


    }

    public  EnvironmentHealerStepDefinitions();

}