package utility

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

var adjectives = []string{
	"Swift", "Brave", "Clever", "Happy", "Lucky", "Mysterious", "Bold", "Fierce", "Noble", "Graceful",
	"Vivid", "Loyal", "Fearless", "Cunning", "Wise", "Radiant", "Silent", "Majestic", "Gentle", "Persistent",
	"Curious", "Agile", "Sharp", "Elegant", "Eager", "Vigorous", "Daring", "Mighty", "Witty", "Strong",
	"Bright", "Persistent", "Resilient", "Fearless", "Imaginative", "Creative", "Charming", "Playful", "Vigorous",
	"Passionate", "Dashing", "Resolute", "Adventurous", "Energetic", "Courageous",
}

var animals = []string{
	"Tiger", "Panda", "Eagle", "Wolf", "Lion", "Fox", "Bear", "Falcon", "Shark", "Rabbit",
	"Elephant", "Zebra", "Cheetah", "Jaguar", "Leopard", "Giraffe", "Hawk", "Owl", "Dragon", "Whale",
	"Buffalo", "Panther", "Raven", "Vulture", "Bison", "Wolfhound", "Penguin", "Koala", "Coyote", "Crocodile",
	"Rhinoceros", "Kangaroo", "Camel", "Alligator", "Otter", "Squid", "Octopus", "Cheetah", "Lynx", "Mole",
	"Seagull", "Tiger Shark", "Wolverine", "Snow Leopard", "Bald Eagle",
}

// 生成唯一昵称
func GenerateUniqueNickname() (string, error) {
	rand.Seed(time.Now().UnixNano())

	nickname := fmt.Sprintf("%s%s%s%s", // 形容词 + 动物名 + 随机字母 + 随机数字
		adjectives[rand.Intn(len(adjectives))],
		animals[rand.Intn(len(animals))],
		randomString(1), // 随机一个字母
		randomDigits(4), // 随机 4 个数字
	)

	return nickname, fmt.Errorf("未能生成唯一昵称")
}

// 随机生成字母
func randomString(n int) string {
	letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
	rand.Seed(time.Now().UnixNano())
	result := make([]rune, n)
	for i := range result {
		result[i] = letters[rand.Intn(len(letters))]
	}
	return string(result)
}

// 随机生成数字
func randomDigits(n int) string {
	digits := []rune("0123456789")
	rand.Seed(time.Now().UnixNano())
	result := make([]rune, n)
	for i := range result {
		result[i] = digits[rand.Intn(len(digits))]
	}
	return string(result)
}
