package session

import (
	

	
	
	
)

func ( []tg.DCOption,  int) string {
	for ,  := range  {
		if .ID !=  {
			continue
		}
		if .TCPObfuscatedOnly ||
			.CDN ||
			.MediaOnly {
			continue
		}

		return .IPAddress
	}

	return ""
}

func ( int,  tdesktop.MTPConfig) Config {
	var  []tg.DCOption
	for ,  := range .DCOptions.Options {
		 = append(, tg.DCOption{
			Flags:             .Flags,
			Ipv6:              .IPv6(),
			MediaOnly:         .MediaOnly(),
			TCPObfuscatedOnly: .TCPOOnly(),
			CDN:               .CDN(),
			Static:            .Static(),
			ID:                int(.ID),
			IPAddress:         .IP,
			Port:              int(.Port),
			Secret:            .Secret,
		})
	}
	return Config{
		DCOptions:       ,
		ThisDC:          ,
		WebfileDCID:     int(.WebFileDCID),
		DCTxtDomainName: .TxtDomainString,
		BlockedMode:     .BlockedMode,
	}
}

// TDesktopSession converts TDesktop's Account to Data.
func ( tdesktop.Account) (*Data, error) {
	 := .Authorization
	 := .Config
	 := .MainDC

	,  := .Keys[]
	if ! {
		return nil, errors.Errorf("key for main DC (%d) not found", )
	}
	 := .ID()

	 := mapConfig(, )
	 := findDCAddr(.DCOptions, )
	if  == "" {
		// Fallback to built-in addrs.
		var  dcs.List
		if !.Environment.Test() {
			 = dcs.Prod()
		} else {
			 = dcs.Test()
		}
		 = findDCAddr(.Options, )
		if  == "" {
			return nil, errors.Errorf("can't find address for DC %d", )
		}
	}

	return &Data{
		DC:        ,
		Addr:      ,
		Config:    ,
		AuthKey:   [:],
		AuthKeyID: [:],
	}, nil
}