package rcuquota

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/tidbcloud/tidb-management-service/nextgen-global-service/domain/entity"
)

func TestCalculateMinRcuByQuota(t *testing.T) {
	tests := []struct {
		name     string
		maxRcu   int64
		quota    *entity.RcuQuota
		expected int64
	}{
		{
			name:   "use provided baseline and coefficient",
			maxRcu: 20000,
			quota: &entity.RcuQuota{
				MinimalRcuBaseline:    5000,
				MinimalRcuCoefficient: 0.25,
			},
			expected: 5000,
		},
		{
			name:   "use dynamic value when larger than baseline",
			maxRcu: 50000,
			quota: &entity.RcuQuota{
				MinimalRcuBaseline:    5000,
				MinimalRcuCoefficient: 0.3,
			},
			expected: 15000,
		},
		{
			name:     "fallback baseline and coefficient",
			maxRcu:   100000,
			quota:    &entity.RcuQuota{},
			expected: 25000,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			assert.Equal(t, tt.expected, CalculateMinRcuByQuota(tt.maxRcu, tt.quota))
		})
	}
}
