package main

import (
	"fmt"

	"github.com/google/uuid"
)

func main() {
	// Generate a new random UUID (v4)
	id := uuid.New()
	fmt.Println("New UUID:", id) // e.g., 6ba7b810-9dad-11d1-80b4-00c04fd430c8

	// Generate UUID as a string directly
	idStr := uuid.NewString()
	fmt.Println("UUID string:", idStr)

	// Parse a UUID from string
	parsed, err := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	if err != nil {
		fmt.Println("Parse error:", err)
		return
	}
	fmt.Println("Parsed:", parsed)

	// Get UUID version and variant
	fmt.Println("Version:", id.Version()) // Version 4
	fmt.Println("Variant:", id.Variant()) // RFC4122

	// Compare UUIDs
	id1 := uuid.New()
	id2 := uuid.New()
	fmt.Println("Same UUID:", id1 == id2) // false

	// Check for nil UUID
	var nilID uuid.UUID
	fmt.Println("Is nil:", nilID == uuid.Nil) // true

	// UUID from bytes
	bytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
	fromBytes, err := uuid.FromBytes(bytes)
	if err != nil {
		fmt.Println("FromBytes error:", err)
		return
	}
	fmt.Println("From bytes:", fromBytes)

	// UUID v5 - Namespace-based (deterministic)
	namespace := uuid.MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	v5 := uuid.NewSHA1(namespace, []byte("example.com"))
	fmt.Println("UUID v5:", v5)

	// Same input always produces same UUID
	v5Again := uuid.NewSHA1(namespace, []byte("example.com"))
	fmt.Println("Deterministic:", v5 == v5Again) // true

	// MustParse - panics on invalid input (useful for constants)
	knownID := uuid.MustParse("550e8400-e29b-41d4-a716-446655440000")
	fmt.Println("Known ID:", knownID)
}
