package client

import (
	"context"

	"github.com/pingcap/log"
	"github.com/tidbcloud/chaos-svc/idl/pbgen/proto/chaos"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func GetChaosSvcGrpcClient(target string) (chaos.ChaosServiceClient, error) {
	log.Info("get chaos-svc grpc client", zap.String("target", target))

	conn, err := grpc.DialContext(
		context.Background(),
		target,
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithChainUnaryInterceptor(),
	)
	if err != nil {
		log.Error("dial chaos-svc", zap.String("error", err.Error()))
		return nil, err
	}

	return chaos.NewChaosServiceClient(conn), nil
}
