package image

// FilterById returns ListImages with specified ID.
func (li ListImages) FilterByID(id uint64) ListImages {
	predicate := func(ri ItemImage) bool {
		return ri.ID == id
	}

	return li.FilterFunc(predicate)
}

// FilterByName returns ListImages with specified Name.
func (li ListImages) FilterByName(name string) ListImages {
	predicate := func(ri ItemImage) bool {
		return ri.Name == name
	}

	return li.FilterFunc(predicate)
}

// FilterByStatus returns ListImages with specified Status.
func (li ListImages) FilterByStatus(status string) ListImages {
	predicate := func(ri ItemImage) bool {
		return ri.Status == status
	}

	return li.FilterFunc(predicate)
}

// FilterByTechStatus returns ListImages with specified TechStatus.
func (li ListImages) FilterByTechStatus(techStatus string) ListImages {
	predicate := func(ri ItemImage) bool {
		return ri.TechStatus == techStatus
	}

	return li.FilterFunc(predicate)
}

// FilterByBootType returns ListImages with specified BootType.
func (li ListImages) FilterByBootType(bootType string) ListImages {
	predicate := func(ri ItemImage) bool {
		return ri.BootType == bootType
	}

	return li.FilterFunc(predicate)
}

// FilterFunc allows filtering ListImages based on a user-specified predicate.
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
	var result ListImages

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

	return result
}

// FindOne returns first found RecordImage
// If none was found, returns an empty struct.
func (li ListImages) FindOne() ItemImage {
	if len(li.Data) == 0 {
		return ItemImage{}
	}

	return li.Data[0]
}
