package netobjgroups

// FilterByID returns NetObjGroupList with specified ID.
func (nog NetObjGroupList) FilterByID(id string) NetObjGroupList {
	predicate := func(netobj RecordNetObjGroup) bool {
		return netobj.ID == id
	}

	return nog.FilterFunc(predicate)
}

// FilterByName returns NetObjGroupList with specified Name.
func (nog NetObjGroupList) FilterByName(name string) NetObjGroupList {
	predicate := func(netobj RecordNetObjGroup) bool {
		return netobj.Name == name
	}

	return nog.FilterFunc(predicate)
}

// FilterFunc allows filtering NetObjGroupList based on a user-specified predicate.
func (nog NetObjGroupList) FilterFunc(predicate func(group RecordNetObjGroup) bool) NetObjGroupList {
	var result NetObjGroupList

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

	return result
}

// FindOne returns first element.
// If none was found, returns an empty struct.
func (nog NetObjGroupList) FindOne() RecordNetObjGroup {
	if len(nog.Objects) == 0 {
		return RecordNetObjGroup{}
	}

	return nog.Objects[0]
}
