package org.example;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class TestDataFactory {

    public static final int ROOT_COUNT = 3;
    public static final int CHILD_COUNT = 2;
    public static final int GRANDCHILD_COUNT = 2;

    public static Set<Pracownik> createTestSet(String mode) {
        Set<Pracownik> roots = createSet(mode);
        int nextCatNumber = 1;

        for (int i = 1; i <= ROOT_COUNT; i++) {
            Set<Pracownik> children = createSet(mode);

            for (int j = 1; j <= CHILD_COUNT; j++) {
                Set<Pracownik> grandchildren = createSet(mode);

                for (int k = 1; k <= GRANDCHILD_COUNT; k++) {
                    grandchildren.add(new Pracownik(
                            "Subsubpracownik-" + i + "-" + j + "-" + k,
                            "Podwładny",
                            3,
                            1000,
                            "Sprzedawca",
                            createSet(mode),
                            getCatImagePath(nextCatNumber++)
                    ));
                }

                children.add(new Pracownik(
                        "Subpracownik-" + i + "-" + j,
                        "Władca",
                        6,
                        2000,
                        "Manager",
                        grandchildren,
                        getCatImagePath(nextCatNumber++)
                ));
            }

            roots.add(new Pracownik(
                    "Pracownik-" + i,
                    "Nadwładca",
                    10,
                    100000,
                    "Zarzadca",
                    children,
                    getCatImagePath(nextCatNumber++)
            ));
        }

        return roots;
    }

    private static String getCatImagePath(int catNumber) {
        return "assets/" + catNumber + ".jpg";
    }

    public static Set<Pracownik> createSet(String mode) {
        switch (mode.toLowerCase()) {
            case "none":
                return new HashSet<>();
            case "natural":
                return new TreeSet<>();
            case "alt":
                return new TreeSet<>(new PracownikAlternativeComparator());
            default:
                throw new IllegalArgumentException("Argument musi być none, natural lub alt");
        }
    }
}
