package etcdclient

import (
	"crypto/tls"
	"time"

	"github.com/pingcap/log"
	"go.etcd.io/etcd/clientv3"
	"go.uber.org/zap"
)

const (
	DefaultDialTimeout = 5 * time.Second
)

// New ... creates etcd v3 client
func New(endpoints []string, tc *tls.Config) (*clientv3.Client, error) {
	cfg := clientv3.Config{
		Endpoints:   endpoints,
		DialTimeout: DefaultDialTimeout,
		TLS:         tc,
	}

	log.Info("create etcd v3 client", zap.Strings("endpoints", endpoints))
	etcdCli, err := clientv3.New(cfg)
	return etcdCli, err
}
