package link;

public class RandomLinkIdGenerator {

	private final LinkRepository linkRepository;

	public RandomLinkIdGenerator(LinkRepository linkRepository) {
		this.linkRepository = linkRepository;
	}

	public LinkId generateId() {
		var randomID = (int) (Math.random() * 10000);

		if (linkRepository.getById(new LinkId(randomID)).isPresent()) {
			return generateId();
		}
		return new LinkId(randomID);
	}
}
