package service

import (
	"context"
	"testing"

	"github.com/stretchr/testify/require"
	apiv1 "github.com/tidbcloud/cluster-service-ng/api/tidbcloud/cluster-agent/v1"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestMarkTiProxyPodUnhealthyLegacyReturnsErrorWhenPodMissing(t *testing.T) {
	scheme := runtime.NewScheme()
	require.NoError(t, corev1.AddToScheme(scheme))

	svc := NewAgentService(fake.NewClientBuilder().WithScheme(scheme).Build(), nil)
	resp, err := svc.MarkTiProxyPodUnhealthyLegacy(context.Background(), &apiv1.MarkTiProxyPodUnhealthyLegacyReq{
		ClusterId: "cluster-1",
		PodName:   "missing-pod",
	})

	require.Nil(t, resp)
	require.Error(t, err)
	require.Equal(t, codes.NotFound, status.Code(err))
}
