package org.project;

import java.util.Scanner;
import static org.project.ConsoleColors.*;

public class Help {
    private Scanner scanner;
    public Help(){
        this.scanner = new Scanner(System.in);
    }

    public void showHelp() {
        while(true) {
            System.out.println("\n" + CYAN + BOLD + "===== Help Menu =====" + RESET);
            System.out.println("What do you need help with, sir?");
            System.out.println("1-What is Java-Knight?");
            System.out.println("2-How to play");
            System.out.println("0-Back");
            System.out.println(CYAN + "=======================" + RESET);
            int choice = getValidIntInput();
            switch (choice) {
                case 1: javaKnight(); break;
                case 2: howTo(); break;
                case 0: return;
                default:
                    System.out.println(RED + "Invalid choice. Please choose a number between 0-2." + RESET);
            }
        }
    }

    private void javaKnight() {
        System.out.println(WHITE + """
                Prologue: The Legend of Javanest
                For centuries, the land of Javanest lived in peace, until a magical Dragon attacked,
                plunging the realm into absolute darkness. With a wicked curse,
                the Dragon transformed the innocent people into horrific monsters:
                Goblins, Skeletons, and Vampires. Retreating to its impenetrable Castle,
                the Dragon divided the three keys to its lair and hid them among these cursed creatures.
                Now, it is your duty to step up and save the land. You must battle these monsters,
                recover the unique key from each monster type, and finally slay the Dragon to
                break the curse and restore peace to Javanest!
                """ + RESET);
        System.out.println(GREEN + "\nPress ENTER to go back..." + RESET);
        scanner.nextLine();
    }

    private void howTo() {
        System.out.println(CYAN + "=== HOW TO PLAY ===" + RESET);
        System.out.println();
        System.out.println("Goal – Defeat enemies to collect three unique keys (Goblin, Skeleton, Vampire), then storm the castle and slay the Dragon.");
        System.out.println();
        System.out.println("Choose Your Class – Start as one of three heroes:");
        System.out.println("  - Knight – High damage.");
        System.out.println("  - Assassin – High stamina.");
        System.out.println("  - Wizard – High health.");
        System.out.println();
        System.out.println("Combat (Turn-Based) – On your turn, choose one action:");
        System.out.println("  1. Light Attack – Moderate damage, costs no mana (your fallback when out of mana).");
        System.out.println("  2. Heavy Attack – High damage, costs mana.");
        System.out.println("  3. Special Ability – Unique class move (highest mana cost).");
        System.out.println("  4. Defend – Reduces or blocks the next enemy attack.");
        System.out.println("  5. Heal – Restores HP, costs mana.");
        System.out.println();
        System.out.println("Progression");
        System.out.println("  - After each victory, your HP and mana fully recover.");
        System.out.println("  - Defeating enemies grants XP → leveling up increases max HP/mana.");
        System.out.println("  - Each enemy has a chance (~20%) to drop its unique key. You only need one key per enemy type.");
        System.out.println();
        System.out.println("Locked Path – The castle option is hidden until you collect all three keys. Only then can you face the final Dragon.");
        System.out.println();
        System.out.println("Game Over – If your HP reaches zero, the game ends.");
        System.out.println();
        System.out.println("> \"Collect the keys. Break the curse. Save Javanest.\"");
        System.out.println(GREEN + "\nPress ENTER to go back..." + RESET);
        scanner.nextLine();
    }

    private int getValidIntInput() {
        while (!scanner.hasNextInt()) {
            System.out.print(RED + "Please enter a valid number: " + RESET);
            scanner.next();
        }
        int input = scanner.nextInt();
        scanner.nextLine(); // Clear buffer
        return input;
    }
}