package utils

import (
	"crypto/md5"
	"encoding/hex"
	"math/rand"
	"strings"
	"time"
)

// GetDeviceId
// @description: 生成设备ID
// @return deviceId 设备ID
func GetDeviceId() (deviceId string) {
	// 创建一个有种子的随机数生成器
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	// 定义可能的字母
	letters := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	// 初始化字符串构建器
	var sb strings.Builder
	// 生成15个随机字母
	for i := 0; i < 15; i++ {
		sb.WriteByte(letters[r.Intn(len(letters))])
	}
	// 计算MD5哈希
	hash := md5.Sum([]byte(sb.String()))
	hashString := hex.EncodeToString(hash[:])

	// 返回49加上MD5哈希的第3个字符开始的部分
	return "49" + hashString[2:]
}

// GetDeviceName
// @description: 生成设备名称
// @return deviceName 设备名称
func GetDeviceName() (deviceName string) {
	firstNames := []string{
		"Oliver", "Emma", "Liam", "Ava", "Noah", "Sophia", "Elijah", "Isabella",
		"James", "Mia", "William", "Amelia", "Benjamin", "Harper", "Lucas", "Evelyn",
		"Henry", "Abigail", "Alexander", "Ella", "Jackson", "Scarlett", "Sebastian",
		"Grace", "Aiden", "Chloe", "Matthew", "Zoey", "Samuel", "Lily", "David",
		"Aria", "Joseph", "Riley", "Carter", "Nora", "Owen", "Luna", "Daniel",
		"Sofia", "Gabriel", "Ellie", "Matthew", "Avery", "Isaac", "Mila", "Leo",
		"Julian", "Layla",
	}

	lastNames := []string{
		"Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis",
		"Rodriguez", "Martinez", "Hernandez", "Lopez", "Gonzalez", "Wilson", "Anderson",
		"Thomas", "Taylor", "Moore", "Jackson", "Martin", "Lee", "Perez", "Thompson",
		"White", "Harris", "Sanchez", "Clark", "Ramirez", "Lewis", "Robinson", "Walker",
		"Young", "Allen", "King", "Wright", "Scott", "Torres", "Nguyen", "Hill",
		"Flores", "Green", "Adams", "Nelson", "Baker", "Hall", "Rivera", "Campbell",
		"Mitchell", "Carter", "Roberts", "Gomez", "Phillips", "Evans",
	}

	// 使用随机数生成器
	r := rand.New(rand.NewSource(time.Now().UnixNano()))

	// 随机选择名字和姓氏
	firstName := firstNames[r.Intn(len(firstNames))]
	lastName := lastNames[r.Intn(len(lastNames))]

	// 返回组合后的字符串
	return firstName + " " + lastName + "'s Pad"
}
