package strutil

import (
	
	
	
	

	
)

// Md5 Generate a 32-bit md5 string
func ( any) string { return string(Md5Bytes()) }

// MD5 Generate a 32-bit md5 string
func ( any) string { return Md5() }

// GenMd5 Generate a 32-bit md5 string
func ( any) string { return Md5() }

// Md5Simple md5 加密原始二进制的每个byte转为 base62,缩短长度(16)
func ( any) string {
	 := byteutil.Md5Sum()
	 := new(strings.Builder)
	.Grow(16)

	// 直接将每个 byte 转为 base62 数字然后拼接
	for ,  := range  {
		.WriteByte(Base62Chars[%0x3E])
	}
	return .String()
}

// Md5Base62 md5 加密原始二进制的转为 base62 字符串,缩短长度(21~22)
func ( any) string {
	 := byteutil.Md5Sum()

	// Step 2: 将字节数组转为 big.Int
	 := new(big.Int)
	.SetBytes()

	// Step 3: 转换为 Base62 字符串
	 := new(strings.Builder)
	// base62.Grow(22)
	for .Sign() > 0 {
		 := new(big.Int)
		.DivMod(, big.NewInt(62), )
		.WriteByte(Base62Chars[.Int64()])
	}

	// 反转字符串以得到正确的顺序
	 := []rune(.String())
	for ,  := 0, len()-1;  < ; ,  = +1, -1 {
		[], [] = [], []
	}

	return string()
}

// Md5Bytes Generate a 32-bit md5 bytes
func ( any) []byte { return byteutil.Md5() }

// ShortMd5 Generate a 16-bit md5 string. remove the first 8 and last 8 bytes from 32-bit md5 string.
func ( any) string { return string(byteutil.ShortMd5()) }

//
// ----------------------- Simple UUID -----------------------------
//

// UUIDv4 Generate a simple UUIDv4 string
func () (string, error) {
	 := make([]byte, 16)
	if ,  := rand.Read();  != nil {
		return "", fmt.Errorf("generate UUID fail: %w", )
	}

	// 设置版本(4)和变体
	[6] = ([6] & 0x0f) | 0x40 // Version 4
	[8] = ([8] & 0x3f) | 0x80 // Variant 10

	return fmt.Sprintf("%x-%x-%x-%x-%x", [0:4], [4:6], [6:8], [8:10], [10:16]), nil
}

// ShortUUID Generate a short UUID (8 characters)
func () string {
	 := make([]byte, 4)
	if ,  := rand.Read();  != nil {
		return fmt.Sprintf("%04x", )
	}
	return fmt.Sprintf("%08x", )
}