package br

import (
	"context"
	"testing"

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

// mockTransactioner is a mock implementation of db.Transactioner for testing
type mockTransactioner struct {
	fn func(ctx context.Context, fn func(ctx context.Context) error) error
}

func newMockTransactioner() *mockTransactioner {
	return &mockTransactioner{
		fn: func(ctx context.Context, fn func(ctx context.Context) error) error {
			return fn(ctx)
		},
	}
}

func (m *mockTransactioner) Transaction(ctx context.Context, fn func(ctx context.Context) error) error {
	return m.fn(ctx, fn)
}

func TestConvertStringArrayToUint64Array(t *testing.T) {
	tests := []struct {
		name        string
		input       []string
		expected    []uint64
		expectError bool
	}{
		{
			name:        "valid string array",
			input:       []string{"1", "2", "3", "123"},
			expected:    []uint64{1, 2, 3, 123},
			expectError: false,
		},
		{
			name:        "empty array",
			input:       []string{},
			expected:    []uint64{},
			expectError: false,
		},
		{
			name:        "single valid number",
			input:       []string{"42"},
			expected:    []uint64{42},
			expectError: false,
		},
		{
			name:        "invalid number",
			input:       []string{"1", "abc", "3"},
			expected:    nil,
			expectError: true,
		},
		{
			name:        "negative number",
			input:       []string{"1", "-2", "3"},
			expected:    nil,
			expectError: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result, err := convertStringArrayToUint64Array(tt.input)

			if tt.expectError {
				require.Error(t, err)
				assert.Nil(t, result)
			} else {
				require.NoError(t, err)
				assert.Equal(t, tt.expected, result)
			}
		})
	}
}
