//package io.delphi.qa.auto.awsmfrw.common_baby.perf.dsl;
//
//import org.apache.jmeter.control.LoopController;
//import org.apache.jmeter.testelement.TestElement;
//import org.apache.jmeter.threads.ThreadGroup;
//import org.apache.jmeter.threads.gui.SetupThreadGroupGui;
//import us.abstracta.jmeter.javadsl.core.DslTestElement;
//import us.abstracta.jmeter.javadsl.core.DslTestPlan;
//import us.abstracta.jmeter.javadsl.core.DslThreadGroup;
//import us.abstracta.jmeter.javadsl.core.TestElementContainer;
//
//import java.time.Duration;
//import java.util.List;
//
//public class IsaDslSetUpThreadGroup extends TestElementContainer<DslThreadGroup.ThreadGroupChild> implements
//    DslTestPlan.TestPlanChild {
//
//
//    private final int threads;
//    private final int iterations;
//    private final Duration duration;
//    private Duration rampUpPeriod = Duration.ZERO;
//
//    public IsaDslSetUpThreadGroup(String name, int threads, int iterations, List<DslThreadGroup.ThreadGroupChild> children) {
//        super(name != null ? name : "Setup Thread Group", SetupThreadGroupGui.class, children);
//        this.threads = threads;
//        this.iterations = iterations;
//        this.duration = null;
//    }
//
//    public IsaDslSetUpThreadGroup(String name, int threads, Duration duration,
//                                  List<DslThreadGroup.ThreadGroupChild> children) {
//        super(name != null ? name : "Thread Group", SetupThreadGroupGui.class, children);
//        this.threads = threads;
//        this.iterations = 0;
//        this.duration = duration;
//    }
//
//    public IsaDslSetUpThreadGroup rampUpPeriod(Duration rampUpPeriod) {
//        this.rampUpPeriod = rampUpPeriod;
//        return this;
//    }
//
//    @Override public IsaDslSetUpThreadGroup children(DslThreadGroup.ThreadGroupChild... children) {
//        return (IsaDslSetUpThreadGroup) super.children(children);
//    }
//
//    @Override
//    public TestElement buildTestElement() {
//        ThreadGroup ret = new ThreadGroup();
//        ret.setNumThreads(threads);
//        ret.setRampUp((int) extractDurationSeconds(rampUpPeriod));
//        LoopController loopController = new LoopController();
//        ret.setSamplerController(loopController);
//        if (duration != null) {
//            loopController.setLoops(-1);
//            ret.setScheduler(true);
//            ret.setDuration(extractDurationSeconds(duration));
//        } else {
//            loopController.setLoops(iterations);
//        }
//        return ret;
//    }
//
//    private long extractDurationSeconds(Duration duration) {
//        return Math.round(Math.ceil((double) duration.toMillis() / 1000));
//    }
//
//    /**
//     * Test elements that can be added as direct children of a thread group in jmeter should implement
//     * this interface.
//     */
//    public interface IsaThreadGroupChild extends DslTestElement {
//
//    }
//}
