package com.example.dateplanner.utils;

import java.util.Random;

public class PasswordGenerator {
    private static final String LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz";
    private static final String UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String NUMBERS = "0123456789";
    private static final String SPECIAL_CHARACTERS = "!@#$%^&*()-_=+[]{}|;:,.<>?";

    private static final String EASY_CHARACTERS = LOWERCASE_LETTERS + UPPERCASE_LETTERS;
    private static final String MEDIUM_CHARACTERS = EASY_CHARACTERS + NUMBERS;
    private static final String HARD_CHARACTERS = MEDIUM_CHARACTERS + SPECIAL_CHARACTERS;

    private static final Random RANDOM = new Random();

    public enum Complexity {
        EASY, MEDIUM, HARD
    }

    public static String generatePassword(int length, Complexity complexity) {
        if (length <= 0) {
            throw new IllegalArgumentException("Password length must be greater than zero");
        }

        StringBuilder password = new StringBuilder(length);
        String characters;

        switch (complexity) {
            case EASY:
                characters = EASY_CHARACTERS;
                break;
            case MEDIUM:
                characters = MEDIUM_CHARACTERS;
                break;
            case HARD:
                characters = HARD_CHARACTERS;
                break;
            default:
                throw new IllegalArgumentException("Invalid complexity level");
        }

        for (int i = 0; i < length; i++) {
            password.append(characters.charAt(RANDOM.nextInt(characters.length())));
        }

        return password.toString();
    }
}
