package uuid

import (
	"testing"

	"github.com/google/uuid"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestGenerator_NewString(t *testing.T) {
	gen := NewGenerator()

	id1 := gen.NewString()
	id2 := gen.NewString()

	// Should be valid UUIDs
	_, err := uuid.Parse(id1)
	require.NoError(t, err)

	_, err = uuid.Parse(id2)
	require.NoError(t, err)

	// Should be different
	assert.NotEqual(t, id1, id2)

	// Should be 36 characters long (standard UUID string format)
	assert.Len(t, id1, 36)
	assert.Len(t, id2, 36)
}

func TestGenerator_NewStringShort(t *testing.T) {
	gen := NewGenerator()

	short1 := gen.NewStringShort()
	short2 := gen.NewStringShort()

	// Should be 8 characters long
	assert.Len(t, short1, 8)
	assert.Len(t, short2, 8)

	// Should be different
	assert.NotEqual(t, short1, short2)

	// Should be hex characters
	assert.Regexp(t, "^[0-9a-f]{8}$", short1)
	assert.Regexp(t, "^[0-9a-f]{8}$", short2)
}

func TestGenerator_New(t *testing.T) {
	gen := NewGenerator()

	id1 := gen.New()
	id2 := gen.New()

	// Should be different
	assert.NotEqual(t, id1, id2)

	// Should be valid UUIDs
	assert.NotEqual(t, uuid.Nil, id1)
	assert.NotEqual(t, uuid.Nil, id2)
}

func TestDefaultFunctions(t *testing.T) {
	// Test default package functions
	id1 := NewString()
	id2 := NewString()

	// Should be valid UUIDs
	_, err := uuid.Parse(id1)
	require.NoError(t, err)

	_, err = uuid.Parse(id2)
	require.NoError(t, err)

	// Should be different
	assert.NotEqual(t, id1, id2)
}

func TestDefaultShortFunction(t *testing.T) {
	short1 := NewStringShort()
	short2 := NewStringShort()

	// Should be 8 characters long
	assert.Len(t, short1, 8)
	assert.Len(t, short2, 8)

	// Should be different
	assert.NotEqual(t, short1, short2)
}

func TestDefaultNewFunction(t *testing.T) {
	id1 := New()
	id2 := New()

	// Should be different
	assert.NotEqual(t, id1, id2)

	// Should be valid UUIDs
	assert.NotEqual(t, uuid.Nil, id1)
	assert.NotEqual(t, uuid.Nil, id2)
}
