package core

import (
	"encoding/hex"
	"testing"
)

func TestRandomHexID(t *testing.T) {
	t.Run("8 bytes retorna 16 caracteres hex validos", func(t *testing.T) {
		got, err := RandomHexID(8)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if len(got) != 16 {
			t.Errorf("expected length 16, got %d", len(got))
		}
		if _, err := hex.DecodeString(got); err != nil {
			t.Errorf("result is not valid hex: %v", err)
		}
	})

	t.Run("dos llamadas devuelven valores distintos", func(t *testing.T) {
		a, err := RandomHexID(8)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		b, err := RandomHexID(8)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if a == b {
			t.Errorf("expected two different IDs, both are %q", a)
		}
	})

	t.Run("numBytes 0 retorna error", func(t *testing.T) {
		_, err := RandomHexID(0)
		if err == nil {
			t.Error("expected error for numBytes=0, got nil")
		}
	})

	t.Run("numBytes negativo retorna error", func(t *testing.T) {
		_, err := RandomHexID(-1)
		if err == nil {
			t.Error("expected error for numBytes=-1, got nil")
		}
	})
}
