package it.micegroup.gestioneferie.configurazionepf.assembler;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Component;

import it.micegroup.gestioneferie.libs.assembler.BaseModelAssembler;
import it.micegroup.gestioneferie.configurazionepf.controller.DpercAutPianFeriePkController;
import it.micegroup.gestioneferie.configurazionepf.dto.DpercAutPianFeriePkDto;
import it.micegroup.gestioneferie.configurazionepf.entity.DpercAutPianFeriePk;

import it.micegroup.gestioneferie.configurazionepf.controller.DpercAutPianFerieHController;

@Component
public class DpercAutPianFeriePkModelAssembler
		extends BaseModelAssembler<DpercAutPianFeriePk, DpercAutPianFeriePkDto, DpercAutPianFeriePkController> {

	@Override
	public DpercAutPianFeriePkDto toModel(DpercAutPianFeriePk dpercAutPianFeriePk) {
		DpercAutPianFeriePkDto dpercAutPianFeriePkDto = map(dpercAutPianFeriePk, DpercAutPianFeriePkDto.class,
				DpercAutPianFeriePkController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DpercAutPianFeriePkController.class).getByObjectKey(dpercAutPianFeriePk.getObjectKey()))
						.withSelfRel());
		dpercAutPianFeriePkDto.add(selfLink);

		// PARENT LINKS

		// CHILDREN LINKS
		if (dpercAutPianFeriePk.getTheDpercAutPianFerieH() != null) {
			Link dpercAutPianFerieHLink = convert(linkTo(methodOn(DpercAutPianFerieHController.class)
					.findByDpercAutPianFeriePk(dpercAutPianFeriePk.getObjectKey(), null))
							.withRel("theDpercAutPianFerieH"));
			dpercAutPianFeriePkDto.add(dpercAutPianFerieHLink);
		}

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dpercAutPianFeriePkDto;

	}

	@Override
	public CollectionModel<DpercAutPianFeriePkDto> toCollectionModel(Iterable<? extends DpercAutPianFeriePk> entities) {
		CollectionModel<DpercAutPianFeriePkDto> collectionEntities = super.toCollectionModel(entities);
		// collectionEntities.add(linkTo(methodOn(OrdineController.class).findPaginated(null,
		// null)).withSelfRel());

		return collectionEntities;
	}

}

