package zone

// FilterByID returns ListZones with specified ID.
func (list ListZones) FilterByID(id uint64) ListZones {
	predicate := func(izone ItemZone) bool {
		return izone.ID == id
	}

	return list.FilterFunc(predicate)
}

// FilterByName returns ListZones with specified Name.
func (list ListZones) FilterByName(name string) ListZones {
	predicate := func(izone ItemZone) bool {
		return izone.Name == name
	}

	return list.FilterFunc(predicate)
}

// FilterByStatus returns ListZones with specified Status.
func (list ListZones) FilterByStatus(status string) ListZones {
	predicate := func(izone ItemZone) bool {
		return izone.Status == status
	}

	return list.FilterFunc(predicate)
}

// FilterFunc allows filtering ListZones based on a user-specified predicate.
func (list ListZones) FilterFunc(predicate func(ItemZone) bool) ListZones {
	var result ListZones

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

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

	return result
}

// FindOne returns first found ItemZone
// If none was found, returns an empty struct.
func (list ListZones) FindOne() ItemZone {
	if list.EntryCount == 0 {
		return ItemZone{}
	}

	return list.Data[0]
}
