package dcs

import (
	

	
)

// FindDCs searches DCs candidates from given config.
func ( []tg.DCOption,  int,  bool) []tg.DCOption {
	// Preallocate slice.
	 := make([]tg.DCOption, 0, 32)

	for ,  := range  {
		if .ID !=  {
			continue
		}
		 = append(, )
	}

	if len() < 1 {
		return nil
	}

	sort.Slice(, func(,  int) bool {
		,  := [], []

		// If we prefer IPv6 and left is IPv6 and right is not, so then
		// left is smaller (would be before right).
		if  {
			if .Ipv6 && !.Ipv6 {
				return true
			}
			if !.Ipv6 && .Ipv6 {
				return false
			}
		}

		// Also we prefer static addresses.
		return .Static && !.Static
	})

	return 
}

// FindPrimaryDCs searches new primary DC from given config.
// Unlike FindDC, it filters CDNs and MediaOnly servers, returns error
// if not found.
func ( []tg.DCOption,  int,  bool) []tg.DCOption {
	 := FindDCs(, , )
	// Filter (in place) from SliceTricks.
	 := 0
	for ,  := range  {
		if !.MediaOnly && !.CDN {
			[] = 
			++
		}
	}
	return [:]
}