/**
 * This function helps the physical therapist manage the exercises for a patient.
 * It allows adding, removing, and modifying exercise details.
 *
 * @param patient The name of the patient.
 * @param exercises A list of exercises the patient is currently performing.
 * @param goalReps A dictionary mapping exercises to the target number of repetitions.
 * @param goalSets A dictionary mapping exercises to the target number of sets.
 */
fun manageExercises(patient: String, exercises: MutableList<String>, goalReps: MutableMap<String, Int>, goalSets: MutableMap<String, Int>) {

    while (true) {
        println("Patient: $patient")
        println("Current Exercises:")
        exercises.forEach { exercise -> println("- $exercise") }
        println()
        
        println("Menu:")
        println("1. Add an exercise")
        println("2. Remove an exercise")
        println("3. Modify exercise details")
        println("4. Exit")
        print("Enter your choice (1-4): ")
        val choice = readLine()?.toIntOrNull() ?: 0
        println()

        when (choice) {
            1 -> {  // Add an exercise
                print("Enter the exercise name: ")
                val exerciseName = readLine() ?: ""
                print("Enter the target number of repetitions: ")
                val reps = readLine()?.toIntOrNull() ?: 0
                goalReps[exerciseName] = reps
                print("Enter the target number of sets: ")
                val sets = readLine()?.toIntOrNull() ?: 0
                goalSets[exerciseName] = sets
            }
            2 -> {  // Remove an exercise
                print("Enter the exercise name to remove: ")
                val exerciseName = readLine() ?: ""
                goalReps.remove(exerciseName)
                goalSets.remove(exerciseName)
            }
            3 -> {  // Modify exercise details
                print("Enter the exercise name to modify: ")
                val exerciseName = readLine() ?: ""
                if (goalReps.containsKey(exerciseName)) {
                    print("Enter the new target number of repetitions: ")
                    val reps = readLine()?.toIntOrNull() ?: 0
                    goalReps[exerciseName] = reps
                    print("Enter the new target number of sets: ")
                    val sets = readLine()?.toIntOrNull() ?: 0
                    goalSets[exerciseName] = sets
                } else {
                    println("Exercise not found.")
                }
            }
            4 -> return
            else -> println("Invalid choice. Please enter a number between 1 and 4.")
        }
    }
}
/**
 * This function helps the physical therapist manage the exercises for a patient.
 * It allows adding, removing, and modifying exercise details.
 *
 * @param patient The name of the patient.
 * @param exercises A list of exercises the patient is currently performing.
 * @param goalReps A dictionary mapping exercises to the target number of repetitions.
 * @param goalSets A dictionary mapping exercises to the target number of sets.
 */
fun manageExercises(patient: String, exercises: MutableList<String>, goalReps: MutableMap<String, Int>, goalSets: MutableMap<String, Int>) {
/**
 * This function helps the physical therapist manage the exercises for a patient.
 * It allows adding, removing, and modifying exercise details.
 *
 * @param patient The name of the patient.
 * @param exercises A list of exercises the patient is currently performing.
 * @param goalReps A dictionary mapping exercises to the target number of repetitions.
 * @param goalSets A dictionary mapping exercises to the target number of sets.
 */
fun manageExercises(patient: String, exercises: MutableList<String>, goalReps: MutableMap<String, Int>, goalSets: MutableMap<String, Int>) {

    while (true) {
        println("Patient: $patient")
        println("Current Exercises:")
        exercises.forEach { exercise -> println("- $exercise") }
        println()
        
        println("Menu:")
        println("1. Add an exercise")
        println("2. Remove an exercise")
        println("3. Modify exercise details")
        println("4. Exit")
        print("Enter your choice (1-4): ")
        val choice = readLine()?.toIntOrNull() ?: 0
        println()

        when (choice) {
            1 -> {  // Add an exercise
                print("Enter the exercise name: ")
                val exerciseName = readLine() ?: ""
                print("Enter the target number of repetitions: ")
                val reps = readLine()?.toIntOrNull() ?: 0
                goalReps[exerciseName] = reps
                print("Enter the target number of sets: ")
                val sets = readLine()?.toIntOrNull() ?: 0
                goalSets[exerciseName] = sets
            }
            2 -> {  // Remove an exercise
                print("Enter the exercise name to remove: ")
                val exerciseName = readLine() ?: ""
                goalReps.remove(exerciseName)
                goalSets.remove(exerciseName)
            }
            3 -> {  // Modify exercise details
                print("Enter the exercise name to modify: ")
                val exerciseName = readLine() ?: ""
                if (goalReps.containsKey(exerciseName)) {
                    print("Enter the new target number of repetitions: ")
                    val reps = readLine()?.toIntOrNull() ?: 0
                    goalReps[exerciseName] = reps
                    print("Enter the new target number of sets: ")
                    val sets = readLine()?.toIntOrNull() ?: 0
                    goalSets[exerciseName] = sets
                } else {
                    println("Exercise not found.")
                }
            }
            4 -> return
            else -> println("Invalid choice. Please enter a number between 1 and 4.")
        }
    }
}