package util

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func AskForConfirmation(s string, defaultVal bool) bool {
	reader := bufio.NewReader(os.Stdin)

	for {
		if defaultVal {
			fmt.Printf("%s [Y/n]: ", s)
		} else {
			fmt.Printf("%s [y/N]: ", s)
		}

		response, _ := reader.ReadString('\n')

		response = strings.ToLower(strings.TrimSpace(response))

		if response == "" {
			return defaultVal
		} else if response == "y" || response == "yes" {
			return true
		} else if response == "n" || response == "no" {
			return false
		}
	}
}
