package eu.gity.jmeter.ddos.stairsddosthreadgrp.charting;

import eu.gity.jmeter.ddos.stairsddosthreadgrp.charting.colors.CustomPalette;
import eu.gity.jmeter.ddos.stairsddosthreadgrp.charting.colors.CycleColors;
import eu.gity.jmeter.ddos.stairsddosthreadgrp.charting.colors.HueRotatePalette;
import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

public class ColorsDispatcherFactory implements Serializable {

    private static final long serialVersionUID = 240L;

    private static final Logger log = LoggerFactory.getLogger(ColorsDispatcherFactory.class);

    public static ColorsDispatcher getColorsDispatcher() {
        String customDispatcher = JMeterUtils.getProperty("jmeterPlugin.customColorsDispatcher");
        String customOptions = JMeterUtils.getProperty("jmeterPlugin.customColorsDispatcher.options");
        if (customDispatcher != null) {
            if (customDispatcher.equalsIgnoreCase("huerotate")) {
                log.debug("customDispatcher hue rotate");
                return new HueRotatePalette(customOptions);
            } else if (customDispatcher.equalsIgnoreCase("custompalette")) {
                log.debug("customDispatcher custom palette");
                return new CustomPalette(customOptions);
            }
        }
        log.debug("Original boring cycle colors");
        return new CycleColors(); // original "cycle" colors dispatcher
    }
}
