package provider

import (
	"testing"

	"github.com/stretchr/testify/require"

	calent "github.com/tidbcloud/devops/entity/k8scalendar"
)

func TestGkeDatePrecision(t *testing.T) {
	tests := []struct {
		in   string
		want string
	}{
		{"2026-Q2", calent.ReleasePrecisionQuarter},
		{"2026-08-03", calent.ReleasePrecisionDay},
		{"2026-08", calent.ReleasePrecisionMonth},
		{"March 2026", calent.ReleasePrecisionMonth},
		{"Aug 3, 2026", calent.ReleasePrecisionDay},
	}
	for _, tc := range tests {
		require.Equal(t, tc.want, gkeDatePrecision(tc.in), tc.in)
	}
}

func TestCoarsestGkePrecision(t *testing.T) {
	require.Equal(t, calent.ReleasePrecisionQuarter,
		coarsestGkePrecision(calent.ReleasePrecisionDay, calent.ReleasePrecisionQuarter, calent.ReleasePrecisionMonth))
	require.Equal(t, calent.ReleasePrecisionDay,
		coarsestGkePrecision(calent.ReleasePrecisionDay, calent.ReleasePrecisionDay))
}

func TestParseGkeScheduleDate(t *testing.T) {
	tm, prec := parseGkeScheduleDate("2026-Q2")
	require.NotNil(t, tm)
	require.Equal(t, calent.ReleasePrecisionQuarter, prec)

	tm, prec = parseGkeScheduleDate("2026-08-03")
	require.NotNil(t, tm)
	require.Equal(t, calent.ReleasePrecisionDay, prec)
}
