package secpolicies

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

	return agl.FilterFunc(predicate)
}

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

	return agl.FilterFunc(predicate)
}

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

	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 SecurityPolicyList) FindOne() SecurityPolicySummary {
	if len(agl) == 0 {
		return SecurityPolicySummary{}
	}

	return agl[0]
}
