package adrspools

// FilterByID returns AddressPoolsList with specified ID.
func (agl AddressPoolsList) FilterByID(id string) AddressPoolsList {
	predicate := func(ia NetworkAddressPool) bool {
		return ia.ID == id
	}

	return agl.FilterFunc(predicate)
}

// FilterByName returns AddressPoolsList with specified Name.
func (agl AddressPoolsList) FilterByName(name string) AddressPoolsList {
	predicate := func(ia NetworkAddressPool) bool {
		return ia.Name == name
	}

	return agl.FilterFunc(predicate)
}

// FilterFunc allows filtering AddressPoolsList based on a user-specified predicate.
func (agl AddressPoolsList) FilterFunc(predicate func(NetworkAddressPool) bool) AddressPoolsList {
	var result AddressPoolsList

	for _, acc := range agl.Pools {
		if predicate(acc) {
			result.Pools = append(result.Pools, acc)
		}
	}

	return result
}

// FindOne returns first element.
// If none was found, returns an empty struct.
func (agl AddressPoolsList) FindOne() NetworkAddressPool {
	if len(agl.Pools) == 0 {
		return NetworkAddressPool{}
	}

	return agl.Pools[0]
}
