package info.knacki.pass.generator;

public class PasswordGenerator {

    public interface PasswordGeneratorParams {
        boolean hasNumbers();
        boolean hasLetters();
        boolean hasCapitalize();
        boolean hasSpecialChar();
        int length();
    }

    @SuppressWarnings("SpellCheckingInspection")
    private static String generateAlphabet(PasswordGeneratorParams wiz) {
        StringBuilder abc = new StringBuilder();
        if (wiz.hasSpecialChar())
            abc.append("&~#'{\"([-|`_\\^@)]=}+%*$?,.;/:/");
        if (wiz.hasLetters())
            abc.append("abcdefghijklmnopqrstuvwxyz");
        if (wiz.hasCapitalize())
            abc.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        if (wiz.hasNumbers() || abc.length() == 0)
            abc.append("0123456789");
        return abc.toString();
    }

    private static int rand(int max) {
        return (int) (Math.random() * max);
    }

    public static String generate(PasswordGeneratorParams wiz) {
        String alphabet = generateAlphabet(wiz);
        StringBuilder result = new StringBuilder();

        for (int i =0; i < wiz.length(); ++i)
            result.append(alphabet.charAt(rand(alphabet.length())));
        return result.toString();
    }
}
