package org.marsik.elshelves.backend.entities.converters;

import org.marsik.elshelves.api.entities.FootprintApiModel;
import org.marsik.elshelves.backend.entities.Footprint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.UUID;

@Service
public class FootprintToEmber implements CachingConverter<Footprint, FootprintApiModel, UUID> {
	@Autowired
	UserToEmber userToEmber;

	@Override
	public FootprintApiModel convert(Footprint object, int nested, Map<UUID, Object> cache) {
		if (object == null) {
			return null;
		}

		if (cache.containsKey(object.getUuid())) {
			return (FootprintApiModel)cache.get(object.getUuid());
		}

		FootprintApiModel model = new FootprintApiModel();
		if (nested > 0) {
			cache.put(object.getUuid(), model);
		}
		return convert(object, model, nested, cache);
	}

	@Override
	public FootprintApiModel convert(Footprint object, FootprintApiModel model, int nested, Map<UUID, Object> cache) {
		model.setName(object.getName());
		model.setId(object.getUuid());
		model.setHoles(object.getHoles());
		model.setPads(object.getPads());
		model.setNpth(object.getNpth());
		model.setKicad(object.getKicad());
		model.setBelongsTo(userToEmber.convert(object.getOwner(), 1, cache));

		return model;
	}
}

@@ -1227,24 +1227,68 @@
 etKicad());%0A
+%0A%09%09if (nested == 0) %7B%0A%09%09%09return model;%0A%09%09%7D%0A%0A
 %09%09model.setB
@@ -1334,16 +1334,25 @@
 Owner(),
+ nested -
  1, cach

Improve FootprintToEmber behaviour when used as nested converter