/*
 * Copyright 2023 CloudWeGo Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package streamclient

import (
	"context"
	"time"

	"github.com/cloudwego/kitex/client"
	"github.com/cloudwego/kitex/pkg/discovery"
	"github.com/cloudwego/kitex/pkg/endpoint"
	"github.com/cloudwego/kitex/pkg/http"
	"github.com/cloudwego/kitex/pkg/loadbalance"
	"github.com/cloudwego/kitex/pkg/loadbalance/lbcache"
	"github.com/cloudwego/kitex/pkg/remote"
	"github.com/cloudwego/kitex/pkg/stats"
	"github.com/cloudwego/kitex/pkg/warmup"
	"github.com/cloudwego/kitex/pkg/xds"
)

// NOTICE: These options are used to inject relevant option configurations into the streaming
// clients that are not based on streamx. After the streamx feature is enabled, you can reuse the apis
// in the client package. Therefore, all apis here will be marked as deprecated.
// For enabling the streamx feature, please refer to https://www.cloudwego.io/docs/kitex/tutorials/basic-feature/streamx/.

// Deprecated: Use client.WithSuite instead, this requires enabling the streamx feature.
func WithSuite(suite client.Suite) Option {
	return ConvertOptionFrom(client.WithSuite(suite))
}

// Deprecated: Use client.WithMiddleware instead, this requires enabling the streamx feature.
func WithMiddleware(mw endpoint.Middleware) Option {
	return ConvertOptionFrom(client.WithMiddleware(mw))
}

// Deprecated: Use client.WithMiddlewareBuilder instead, this requires enabling the streamx feature.
func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder) Option {
	return ConvertOptionFrom(client.WithMiddlewareBuilder(mwb))
}

// Deprecated: Use client.WithInstanceMW instead, this requires enabling the streamx feature.
func WithInstanceMW(mw endpoint.Middleware) Option {
	return ConvertOptionFrom(client.WithInstanceMW(mw))
}

// Deprecated: Use client.WithDestService instead, this requires enabling the streamx feature.
func WithDestService(svr string) Option {
	return ConvertOptionFrom(client.WithDestService(svr))
}

// Deprecated: Use client.WithHostPorts instead, this requires enabling the streamx feature.
func WithHostPorts(hostPorts ...string) Option {
	return ConvertOptionFrom(client.WithHostPorts(hostPorts...))
}

// Deprecated: Use client.WithResolver instead, this requires enabling the streamx feature.
func WithResolver(r discovery.Resolver) Option {
	return ConvertOptionFrom(client.WithResolver(r))
}

// Deprecated: Use client.WithHTTPResolver instead, this requires enabling the streamx feature.
func WithHTTPResolver(r http.Resolver) Option {
	return ConvertOptionFrom(client.WithHTTPResolver(r))
}

// Deprecated: Use client.WithLoadBalancer instead, this requires enabling the streamx feature.
func WithLoadBalancer(lb loadbalance.Loadbalancer, opts ...*lbcache.Options) Option {
	return ConvertOptionFrom(client.WithLoadBalancer(lb, opts...))
}

// Deprecated: Use client.WithConnectTimeout instead, this requires enabling the streamx feature.
func WithConnectTimeout(d time.Duration) Option {
	return ConvertOptionFrom(client.WithConnectTimeout(d))
}

// Deprecated: Use client.WithTag instead, this requires enabling the streamx feature.
func WithTag(key, val string) Option {
	return ConvertOptionFrom(client.WithTag(key, val))
}

// Deprecated: Use client.WithTracer instead, this requires enabling the streamx feature.
func WithTracer(c stats.Tracer) Option {
	return ConvertOptionFrom(client.WithTracer(c))
}

// Deprecated: Use client.WithStatsLevel instead, this requires enabling the streamx feature.
func WithStatsLevel(level stats.Level) Option {
	return ConvertOptionFrom(client.WithStatsLevel(level))
}

// Deprecated: Use client.WithPayloadCodec instead, this requires enabling the streamx feature.
func WithPayloadCodec(c remote.PayloadCodec) Option {
	return ConvertOptionFrom(client.WithPayloadCodec(c))
}

// Deprecated: Use client.WithConnReporterEnabled instead, this requires enabling the streamx feature.
func WithConnReporterEnabled() Option {
	return ConvertOptionFrom(client.WithConnReporterEnabled())
}

// Deprecated: Use client.WithWarmingUp instead, this requires enabling the streamx feature.
func WithWarmingUp(wuo *warmup.ClientOption) Option {
	return ConvertOptionFrom(client.WithWarmingUp(wuo))
}

// Deprecated: Use client.WithXDSSuite instead, this requires enabling the streamx feature.
func WithXDSSuite(suite xds.ClientSuite) Option {
	return ConvertOptionFrom(client.WithXDSSuite(suite))
}

// Deprecated: Use client.WithContextBackup instead, this requires enabling the streamx feature.
func WithContextBackup(backupHandler func(prev, cur context.Context) (ctx context.Context, backup bool)) Option {
	return ConvertOptionFrom(client.WithContextBackup(backupHandler))
}
