package main

import (
	"cmp"
	"fmt"
)

type Product struct {
	Name  string
	Price float64
}

func main() {
	// Compare returns -1, 0, or +1 for ordering
	fmt.Println("Compare Examples:")
	fmt.Printf("cmp.Compare(1, 2) = %d\n", cmp.Compare(1, 2))   // -1
	fmt.Printf("cmp.Compare(2, 2) = %d\n", cmp.Compare(2, 2))   // 0
	fmt.Printf("cmp.Compare(3, 2) = %d\n", cmp.Compare(3, 2))   // +1
	fmt.Printf("cmp.Compare(\"a\", \"b\") = %d\n", cmp.Compare("a", "b"))

	// Less returns true if x < y
	fmt.Println("\nLess Examples:")
	fmt.Printf("cmp.Less(1, 2) = %v\n", cmp.Less(1, 2))   // true
	fmt.Printf("cmp.Less(2, 2) = %v\n", cmp.Less(2, 2))   // false
	fmt.Printf("cmp.Less(3, 2) = %v\n", cmp.Less(3, 2))   // false

	// Or returns the first non-zero value (useful for sorting by multiple fields)
	fmt.Println("\nOr Examples:")
	products := []Product{
		{"Apple", 1.50},
		{"Apple", 0.99},
		{"Banana", 0.75},
	}

	// Multi-field comparison: first by name, then by price
	for i := 0; i < len(products)-1; i++ {
		for j := i + 1; j < len(products); j++ {
			result := cmp.Or(
				cmp.Compare(products[i].Name, products[j].Name),
				cmp.Compare(products[i].Price, products[j].Price),
			)
			fmt.Printf("%s($%.2f) vs %s($%.2f) = %d\n",
				products[i].Name, products[i].Price,
				products[j].Name, products[j].Price,
				result)
		}
	}
}
