package me.atam.atam4j;

import io.dropwizard.setup.Environment;
import me.atam.atam4j.health.AcceptanceTestsState;

import java.util.concurrent.TimeUnit;

public class AcceptanceTestHealthCheckManager {

    private AcceptanceTestsRunnerTaskScheduler acceptanceTestsRunnerTaskScheduler;
    private AcceptanceTestsHealthCheckInitializer acceptanceTestsHealthCheckInitializer;

    public AcceptanceTestHealthCheckManager(AcceptanceTestsRunnerTaskScheduler acceptanceTestsRunnerTaskScheduler, AcceptanceTestsHealthCheckInitializer acceptanceTestsHealthCheckInitializer) {
        this.acceptanceTestsRunnerTaskScheduler = acceptanceTestsRunnerTaskScheduler;
        this.acceptanceTestsHealthCheckInitializer = acceptanceTestsHealthCheckInitializer;
    }

    public void initialise() {
        acceptanceTestsRunnerTaskScheduler.scheduleAcceptanceTestsRunnerTask();
        acceptanceTestsHealthCheckInitializer.initialize();
    }

    public static class AcceptanceTestsRunnerTaskSchedulerBuilder{

        private AcceptanceTestsState acceptanceTestsState = new AcceptanceTestsState();
        private Environment environment = null;
        private Class testClasses[] = null;
        private long initialDelay = 0;
        private long period = 1;
        private TimeUnit unit = TimeUnit.SECONDS;


        public AcceptanceTestsRunnerTaskSchedulerBuilder withAcceptanceTestsState(AcceptanceTestsState acceptanceTestsState) {
            this.acceptanceTestsState = acceptanceTestsState;
            return this;
        }

        public AcceptanceTestsRunnerTaskSchedulerBuilder withEnvironment(Environment environment) {
            this.environment = environment;
            return this;
        }

        public AcceptanceTestsRunnerTaskSchedulerBuilder withTestClasses(Class[] testClasses) {
            this.testClasses = testClasses;
            return this;
        }

        public AcceptanceTestsRunnerTaskSchedulerBuilder withInitialDelay(long initialDelay) {
            this.initialDelay = initialDelay;
            return this;
        }

        public AcceptanceTestsRunnerTaskSchedulerBuilder withPeriod(long period) {
            this.period = period;
            return this;
        }

        public AcceptanceTestsRunnerTaskSchedulerBuilder withUnit(TimeUnit unit) {
            this.unit = unit;
            return this;
        }

        public AcceptanceTestHealthCheckManager build(){

            if (environment == null){
                throw new IllegalStateException("No Environment specified");
            }

            if (testClasses == null){
                throw new IllegalStateException("No test classes specified");
            }


            return new AcceptanceTestHealthCheckManager(
                    new AcceptanceTestsRunnerTaskScheduler(
                        environment,
                        testClasses,
                        acceptanceTestsState,
                        initialDelay,
                        period,
                        unit),
                    new AcceptanceTestsHealthCheckInitializer(
                        acceptanceTestsState,
                        environment));
        }
    }



}
@@ -485,16 +485,60 @@
 heduler,
+%0A                                           
  Accepta
@@ -1343,17 +1343,16 @@
 CONDS;%0A%0A
-%0A
         
@@ -2458,16 +2458,17 @@
  build()
+ 
 %7B%0A%0A     
@@ -2490,32 +2490,33 @@
 ronment == null)
+ 
 %7B%0A              
@@ -2629,16 +2629,17 @@
 == null)
+ 
 %7B%0A      
@@ -2725,17 +2725,16 @@
      %7D%0A%0A
-%0A
         
@@ -3227,12 +3227,9 @@
 %7D%0A    %7D%0A
-%0A%0A%0A
 %7D

Improve formatting