package be.iminds.ilabt.jfed.highlevel.jobs;

import be.iminds.ilabt.jfed.highlevel.stitcher.StitchingTestSetupConfig;
import be.iminds.ilabt.jfed.highlevel.stitcher.StitchingTestSetupConfigBuilder;
import org.testng.annotations.DataProvider;

import java.util.ArrayList;
import java.util.List;

/**
 * User: twalcari
 * Date: 12/9/2015
 * Time: 11:14
 */
public class StitchingTestDataProviders {
    @DataProvider(name = "allStitchingSetupConfigs")
    public static Object[][] getAllStitchingSetupConfigs() {
        List<StitchingTestSetupConfig> configs = new ArrayList<>();

        StitchingTestSetupConfigBuilder confBuilder = new StitchingTestSetupConfigBuilder();
        for (final boolean fakeAm3 : new boolean[] { false, true} ) {
            confBuilder.setHasFakeAm3(fakeAm3);
            for (final boolean am2DependsOnAm1 : new boolean[] { false, true} ) {
                confBuilder.setAm2DependsOnAm1(am2DependsOnAm1);
                for (final StitchingTestSetupConfigBuilder.AmVersion am1v :
                        new StitchingTestSetupConfigBuilder.AmVersion[]{StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3}) {
                    confBuilder.setAmVersion(1, am1v);
                    for (final StitchingTestSetupConfigBuilder.AmVersion am2v :
                            new StitchingTestSetupConfigBuilder.AmVersion[]{StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3}) {
                        confBuilder.setAmVersion(2, am2v);
                        for (final boolean am1supportsAny : new boolean[]{false, true}) {
                            confBuilder.setSupportsAny(1, am1supportsAny);
                            for (final boolean am2supportsAny : new boolean[]{false, true}) {
                                confBuilder.setSupportsAny(2, am2supportsAny);
                                StitchingTestSetupConfig conf = confBuilder.build();
                                configs.add(conf);
                            }
                        }
                    }
                }
            }
        }

        Object[][] res = new Object[configs.size()][];
        int i = 0;
        for (StitchingTestSetupConfig c : configs)
            res[i++] = new Object[] { c };
        return res;
    }

    @DataProvider(name = "allNoVlanStitchingSetupConfigs")
    public static Object[][] getAllNoVlanStitchingSetupConfigs() {
        List<StitchingTestSetupConfig> configs = new ArrayList<>();

        for (int amIndex : new int[] {1, 2}) {
            StitchingTestSetupConfigBuilder confBuilder = new StitchingTestSetupConfigBuilder();
            confBuilder.addSpecialReply(amIndex, StitchingTestSetupConfig.SpecialReply.ERROR_NO_VLANS);
            confBuilder.setAm2DependsOnAm1(true/*am2DependsOnAm1*/);

            for (final StitchingTestSetupConfigBuilder.AmVersion am1v :
                    new StitchingTestSetupConfigBuilder.AmVersion[] { StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3} ) {
                confBuilder.setAmVersion(1, am1v);
                confBuilder.setAmVersion(2, am1v);
                for (final boolean am1supportsAny : new boolean[]{false, true}) {
                    confBuilder.setSupportsAny(1, am1supportsAny);
                    for (final boolean am2supportsAny : new boolean[]{false, true}) {
                        confBuilder.setSupportsAny(2, am2supportsAny);
                        StitchingTestSetupConfig conf = confBuilder.build();
                        configs.add(conf);
                    }
                }
            }

        }

        Object[][] res = new Object[configs.size()][];
        int i = 0;
        for (StitchingTestSetupConfig c : configs)
            res[i++] = new Object[] { c };
        return res;
    }

    /**
     * All combinations of 2 servers with AMv2 or V3 and any support or not
     * Tests using this will lickely change somerthing in the config before using it.
     * */
    @DataProvider(name = "all32anyCombinations")
    public static Object[][] getAll32anyCombinations() {
        List<StitchingTestSetupConfig> configs = new ArrayList<>();

        StitchingTestSetupConfigBuilder confBuilder = new StitchingTestSetupConfigBuilder();
//        confBuilder.setAm2DependsOnAm1(true/*am2DependsOnAm1*/);
//        confBuilder.setSpecialCase(StitchingTestSetupConfig.SpecialCase.am1NoMatchingVlansAm2);

        for (final StitchingTestSetupConfigBuilder.AmVersion am1v :
                new StitchingTestSetupConfigBuilder.AmVersion[] { StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3} ) {
            for (final StitchingTestSetupConfigBuilder.AmVersion am2v :
                    new StitchingTestSetupConfigBuilder.AmVersion[] { StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3} ) {
                confBuilder.setAmVersion(1, am1v);
                confBuilder.setAmVersion(2, am2v);
                for (final boolean am1supportsAny : new boolean[]{false, true}) {
                    confBuilder.setSupportsAny(1, am1supportsAny);
                    for (final boolean am2supportsAny : new boolean[]{false, true}) {
                        confBuilder.setSupportsAny(2, am2supportsAny);
                        StitchingTestSetupConfig conf = confBuilder.build();
                        configs.add(conf);
                    }
                }
            }
        }

        Object[][] res = new Object[configs.size()][];
        int i = 0;
        for (StitchingTestSetupConfig c : configs)
            res[i++] = new Object[] { c };
        return res;
    }

    @DataProvider(name = "33anyany-dep")
    public static Object[][] get33anyany() {
        List<StitchingTestSetupConfig> configs = new ArrayList<>();

        StitchingTestSetupConfigBuilder confBuilder = new StitchingTestSetupConfigBuilder();
        confBuilder.setAm2DependsOnAm1(true/*am2DependsOnAm1*/);
//        confBuilder.setSpecialCase(StitchingTestSetupConfig.SpecialCase.am1NoMatchingVlansAm2);

        confBuilder.setAmVersion(1, StitchingTestSetupConfigBuilder.AmVersion.V3);
        confBuilder.setAmVersion(2, StitchingTestSetupConfigBuilder.AmVersion.V3);
        confBuilder.setSupportsAny(1, true);
        confBuilder.setSupportsAny(2, true);
        StitchingTestSetupConfig conf = confBuilder.build();
        configs.add(conf);


        Object[][] res = new Object[configs.size()][];
        int i = 0;
        for (StitchingTestSetupConfig c : configs)
            res[i++] = new Object[] { c };
        return res;
    }

    @DataProvider(name = "22noanynoany-no_dep")
    public static Object[][] get22noanynoany() {
        List<StitchingTestSetupConfig> configs = new ArrayList<>();

        StitchingTestSetupConfigBuilder confBuilder = new StitchingTestSetupConfigBuilder();
        confBuilder.setAm2DependsOnAm1(false/*am2DependsOnAm1*/);
//        confBuilder.setSpecialCase(StitchingTestSetupConfig.SpecialCase.am1NoMatchingVlansAm2);

        confBuilder.setAmVersion(1, StitchingTestSetupConfigBuilder.AmVersion.V2);
        confBuilder.setAmVersion(2, StitchingTestSetupConfigBuilder.AmVersion.V2);
        confBuilder.setSupportsAny(1, false);
        confBuilder.setSupportsAny(2, false);
        StitchingTestSetupConfig conf = confBuilder.build();
        configs.add(conf);


        Object[][] res = new Object[configs.size()][];
        int i = 0;
        for (StitchingTestSetupConfig c : configs)
            res[i++] = new Object[] { c };
        return res;
    }

    /**
     * All combinations of 2 servers with AMv2 or V3 and any support or not
     * Tests using this will lickely change somerthing in the config before using it.
     * */
    @DataProvider(name = "all32Combinations")
    public static Object[][] getAll32Combinations() {
        List<StitchingTestSetupConfig> configs = new ArrayList<>();

        StitchingTestSetupConfigBuilder confBuilder = new StitchingTestSetupConfigBuilder();
//        confBuilder.setAm2DependsOnAm1(true/*am2DependsOnAm1*/);
//        confBuilder.setSpecialCase(StitchingTestSetupConfig.SpecialCase.am1NoMatchingVlansAm2);

        for (final StitchingTestSetupConfigBuilder.AmVersion am1v :
                new StitchingTestSetupConfigBuilder.AmVersion[] { StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3} ) {
            for (final StitchingTestSetupConfigBuilder.AmVersion am2v :
                    new StitchingTestSetupConfigBuilder.AmVersion[]{StitchingTestSetupConfigBuilder.AmVersion.V2, StitchingTestSetupConfigBuilder.AmVersion.V3}) {
                confBuilder.setAmVersion(1, am1v);
                confBuilder.setAmVersion(2, am2v);
                confBuilder.setSupportsAny(1, true);
                confBuilder.setSupportsAny(2, true);
                StitchingTestSetupConfig conf = confBuilder.build();
                configs.add(conf);
            }
        }

        Object[][] res = new Object[configs.size()][];
        int i = 0;
        for (StitchingTestSetupConfig c : configs)
            res[i++] = new Object[] { c };
        return res;
    }



}
