package category;

public class RandomCategoryIdGenerator implements CategoryIdGenerator {

	private final CategoryRepository categoryRepository;

	public RandomCategoryIdGenerator(CategoryRepository categoryRepository) {
		this.categoryRepository = categoryRepository;
	}

	@Override
	public CategoryId generateId() {
		var randomID = (int) (Math.random() * 10000);

		if (categoryRepository.getById(new CategoryId(randomID)).isPresent()) {
			return generateId();
		}
		return new CategoryId(randomID);
	}
}
