package telegram

import (
	

	

	
	
	
	
	
	
	
)

type clientHandler struct {
	client *Client
}

func ( clientHandler) ( tg.Config,  mtproto.Session) error {
	return .client.onSession(, )
}

func ( clientHandler) ( *bin.Buffer) error {
	return .client.handleUpdates()
}

func ( *Client) () manager.Handler {
	return clientHandler{
		client: ,
	}
}

type connConstructor func(
	create mtproto.Dialer,
	mode manager.ConnMode,
	appID int,
	opts mtproto.Options,
	connOpts manager.ConnOptions,
) pool.Conn

func () connConstructor {
	return func(
		 mtproto.Dialer,
		 manager.ConnMode,
		 int,
		 mtproto.Options,
		 manager.ConnOptions,
	) pool.Conn {
		return manager.CreateConn(, , , , )
	}
}

func ( *Client) () dcs.List {
	 := .cfg.Load()
	return dcs.List{
		Options: .DCOptions,
		Domains: .domains,
		Test:    .testDC,
	}
}

func ( *Client) ( int) mtproto.Dialer {
	return func( context.Context) (transport.Conn, error) {
		return .resolver.Primary(, , .dcList())
	}
}

func ( *Client) ( manager.SetupCallback) pool.Conn {
	return .createConn(0, .defaultMode, )
}

func ( *Client) (
	 int64,
	 manager.ConnMode,
	 manager.SetupCallback,
) pool.Conn {
	,  := .session.Options(.opts)
	.Logger = .log.Named("conn").With(
		zap.Int64("conn_id", ),
		zap.Int("dc_id", .DC),
	)

	return .create(
		.primaryDC(.DC), , .appID,
		, manager.ConnOptions{
			DC:      .DC,
			Test:    .testDC,
			Device:  .device,
			Handler: .asHandler(),
			Setup:   ,
		},
	)
}