package qospolicy

// FilterByID returns ListQoSPolicies with specified ID
func (lqp ListQoSPolicies) FilterByID(id uint64) ListQoSPolicies {
	predicate := func(iqp ItemQoSPolicy) bool {
		return iqp.ID == id
	}

	return lqp.FilterFunc(predicate)
}

// FilterByName returns ListQoSPolicies with specified Name
func (lqp ListQoSPolicies) FilterByName(name string) ListQoSPolicies {
	predicate := func(iqp ItemQoSPolicy) bool {
		return iqp.Name == name
	}

	return lqp.FilterFunc(predicate)
}

// FilterByAccountID returns ListQoSPolicies with specified AccountID
func (lqp ListQoSPolicies) FilterByAccountID(accountID uint64) ListQoSPolicies {
	predicate := func(iqp ItemQoSPolicy) bool {
		return iqp.AccountID == accountID
	}

	return lqp.FilterFunc(predicate)
}

// FilterByStatus returns ListQoSPolicies with specified Status
func (lqp ListQoSPolicies) FilterByStatus(status string) ListQoSPolicies {
	predicate := func(iqp ItemQoSPolicy) bool {
		return iqp.Status == status
	}

	return lqp.FilterFunc(predicate)
}

// FilterByDescription returns ListQoSPolicies with specified Description
func (lqp ListQoSPolicies) FilterByDescription(description string) ListQoSPolicies {
	predicate := func(iqp ItemQoSPolicy) bool {
		return iqp.Description == description
	}

	return lqp.FilterFunc(predicate)
}

// FilterFunc allows filtering ListQoSPolicies based on a user-specified predicate
func (lqp ListQoSPolicies) FilterFunc(predicate func(ItemQoSPolicy) bool) ListQoSPolicies {
	var result ListQoSPolicies

	for _, item := range lqp.Data {
		if predicate(item) {
			result.Data = append(result.Data, item)
		}
	}

	result.EntryCount = uint64(len(result.Data))

	return result
}

// FindOne returns first found ListQoSPolicies
// If none was found, returns an empty struct
func (lqp ListQoSPolicies) FindOne() ItemQoSPolicy {
	if len(lqp.Data) == 0 {
		return ItemQoSPolicy{}
	}

	return lqp.Data[0]
}
