package manager

import (
	
	

	

	
	
	
	
)

// SetupCallback is an optional setup connection callback.
type SetupCallback = func(ctx context.Context, invoker tg.Invoker) error

// ConnOptions is a Telegram client connection options.
type ConnOptions struct {
	DC      int
	Test    bool
	Device  DeviceConfig
	Handler Handler
	Setup   SetupCallback
	Backoff func(ctx context.Context) backoff.BackOff
}

func ( clock.Clock) func( context.Context) backoff.BackOff {
	return func( context.Context) backoff.BackOff {
		 := backoff.NewExponentialBackOff()
		.Clock = 
		.MaxElapsedTime = time.Second * 30
		.MaxInterval = time.Second * 5
		return backoff.WithContext(, )
	}
}

// setDefaults sets default values.
func ( *ConnOptions) ( clock.Clock) {
	if .DC == 0 {
		.DC = 2
	}
	// It's okay to use zero value Test.
	.Device.SetDefaults()
	if .Handler == nil {
		.Handler = NoopHandler{}
	}
	if .Backoff == nil {
		.Backoff = defaultBackoff()
	}
}

// CreateConn creates new connection.
func (
	 mtproto.Dialer,
	 ConnMode,
	 int,
	 mtproto.Options,
	 ConnOptions,
) *Conn {
	.setDefaults(.Clock)
	 := &Conn{
		mode:        ,
		appID:       ,
		device:      .Device,
		clock:       .Clock,
		handler:     .Handler,
		sessionInit: tdsync.NewReady(),
		gotConfig:   tdsync.NewReady(),
		dead:        tdsync.NewReady(),
		setup:       .Setup,
		connBackoff: .Backoff,
	}

	.log = .Logger
	.DC = .DC
	if .Test {
		// New key exchange algorithm requires DC ID and uses mapping like MTProxy.
		// +10000 for test DC, *-1 for media-only.
		.DC += 10000
	}
	.Handler = 
	.Logger = .log.Named("mtproto")
	.proto = mtproto.New(, )

	return 
}