package utils

import (
	"fmt"
	"os"

	"github.com/cespare/xxhash/v2"
)

// ComputeXXH64 computes the XXH64 hash of a file with seed=0.
// Returns the hash as a 16-character lowercase hexadecimal string.
func ComputeXXH64(filepath string) (string, error) {
	// Read entire file as binary data
	data, err := os.ReadFile(filepath)
	if err != nil {
		return "", fmt.Errorf("failed to read file: %w", err)
	}

	// Compute XXH64 hash with default seed=0
	hashValue := xxhash.Sum64(data)

	// Format as 16-character lowercase hex with zero-padding
	// %016x = hex, lowercase, zero-padded to 16 chars
	return fmt.Sprintf("%016x", hashValue), nil
}