package vfpool

// FilterByID returns ListVFPool with specified ID.
func (lvfp ListVFPool) FilterByID(id uint64) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		return ivfp.ID == id
	}

	return lvfp.FilterFunc(predicate)
}

// FilterByGID returns ListVFPool with specified GID.
func (lvfp ListVFPool) FilterByGID(gid uint64) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		return ivfp.GID == gid
	}

	return lvfp.FilterFunc(predicate)
}

// FilterByName returns ListVFPool with specified Name.
func (lvfp ListVFPool) FilterByName(name string) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		return ivfp.Name == name
	}

	return lvfp.FilterFunc(predicate)
}

// FilterByDescription returns ListVFPool with specified Description.
func (lvfp ListVFPool) FilterByDescription(description string) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		return ivfp.Description == description
	}

	return lvfp.FilterFunc(predicate)
}

// FilterByStatus returns ListVFPool with specified Status.
func (lvfp ListVFPool) FilterByStatus(status string) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		return ivfp.Status == status
	}

	return lvfp.FilterFunc(predicate)
}

// FilterByAccountAccess returns ListVFPool with specified AccountAccess.
func (lvfp ListVFPool) FilterByAccountAccess(accountAccess uint64) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		for _, i := range ivfp.AccountAccess {
			if i == accountAccess {
				return true
			}
		}
		return false
	}

	return lvfp.FilterFunc(predicate)
}

// FilterByRGAccess returns ListVFPool with specified RGAccess.
func (lvfp ListVFPool) FilterByRGAccess(rgAccess uint64) ListVFPool {
	predicate := func(ivfp ItemVFPool) bool {
		for _, i := range ivfp.RGAccess {
			if i == rgAccess {
				return true
			}
		}
		return false
	}

	return lvfp.FilterFunc(predicate)
}

// FilterFunc allows filtering ListVFPool based on a user-specified predicate.
func (lvfp ListVFPool) FilterFunc(predicate func(ItemVFPool) bool) ListVFPool {
	var result ListVFPool

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

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

	return result
}

// FindOne returns first found ItemVFPool
// If none was found, returns an empty struct.
func (lvfp ListVFPool) FindOne() ItemVFPool {
	if lvfp.EntryCount == 0 {
		return ItemVFPool{}
	}

	return lvfp.Data[0]
}
