package compatibility

import (
	"reflect"
	"testing"

	catalogv1 "github.com/pingcap-inc/nexuscrm-contract/wire-go/gen/catalog/v1"
)

// ConsumerViewServiceClient shipped before AppMetadataView V3. Freezing its
// method set protects downstream handwritten adapters and mocks from an
// otherwise protobuf-additive but Go-source-breaking interface expansion.
func TestConsumerViewServiceClientRetainsPublishedMethodSet(t *testing.T) {
	client := reflect.TypeOf((*catalogv1.ConsumerViewServiceClient)(nil)).Elem()
	want := []string{
		"GetAppMetadataView",
		"GetAppMetadataViewV2",
		"GetIntegrationBindingView",
		"WatchAppMetadataView",
		"WatchAppMetadataViewV2",
		"WatchIntegrationBindingView",
	}
	if client.NumMethod() != len(want) {
		t.Fatalf("ConsumerViewServiceClient has %d methods, want published %d", client.NumMethod(), len(want))
	}
	for _, name := range want {
		if _, ok := client.MethodByName(name); !ok {
			t.Fatalf("ConsumerViewServiceClient is missing published method %s", name)
		}
	}
}

func TestAppMetadataViewV3UsesSeparateClientInterface(t *testing.T) {
	client := reflect.TypeOf((*catalogv1.AppMetadataViewV3ServiceClient)(nil)).Elem()
	want := []string{"GetAppMetadataViewV3", "WatchAppMetadataViewV3"}
	if client.NumMethod() != len(want) {
		t.Fatalf("AppMetadataViewV3ServiceClient has %d methods, want %d", client.NumMethod(), len(want))
	}
	for _, name := range want {
		if _, ok := client.MethodByName(name); !ok {
			t.Fatalf("AppMetadataViewV3ServiceClient is missing method %s", name)
		}
	}
}
