package helpers

import (
	"fmt"
	"strings"
	"math/rand"
	"time"
	"strconv"
)

var r = rand.New(rand.NewSource(time.Now().UnixNano()))

func Ask(str string) bool {
	var input string
	fmt.Printf("-> %s (Y/n): ", str)
	fmt.Scanln(&input)
	input = strings.TrimSpace(input)
	input = strings.ToLower(input)
	if input != "y" && input != "" && input != "yes" {	
		return false
	}
	return true
}

func ToString(v interface{}) string {
	switch val := v.(type) {
	case int:
		return strconv.Itoa(val)
	case float64:
		return strconv.FormatFloat(val, 'f', -1, 64)
	case string:
		return val
	default:
		return ""
	}
}

func RandStr(n int) string {
    b := make([]byte, n)
    for i := range b {
        b[i] = byte(r.Intn(26) + 'a')
    }
    return string(b)
}
