package routers

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

	return agl.FilterFunc(predicate)
}

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

	return agl.FilterFunc(predicate)
}

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

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

	return result
}

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

	return agl[0]
}
