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.DpercAutPianFerieHController;
import it.micegroup.gestioneferie.configurazionepf.dto.DpercAutPianFerieHDto;
import it.micegroup.gestioneferie.configurazionepf.entity.DpercAutPianFerieH;

import it.micegroup.gestioneferie.configurazionepf.controller.DpercAutPianFeriePkController;
import it.micegroup.gestioneferie.configurazionepf.controller.DconfigPaPianiFerieController;

@Component
public class DpercAutPianFerieHModelAssembler
		extends BaseModelAssembler<DpercAutPianFerieH, DpercAutPianFerieHDto, DpercAutPianFerieHController> {

	@Override
	public DpercAutPianFerieHDto toModel(DpercAutPianFerieH dpercAutPianFerieH) {
		DpercAutPianFerieHDto dpercAutPianFerieHDto = map(dpercAutPianFerieH, DpercAutPianFerieHDto.class,
				DpercAutPianFerieHController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DpercAutPianFerieHController.class).getByObjectKey(dpercAutPianFerieH.getObjectKey()))
						.withSelfRel());
		dpercAutPianFerieHDto.add(selfLink);

		// PARENT LINKS
		if (dpercAutPianFerieH.getTheDpercAutPianFeriePk() != null) {
			Link dpercAutPianFeriePkLink = convert(linkTo(methodOn(DpercAutPianFeriePkController.class)
					.getByObjectKey(dpercAutPianFerieH.getTheDpercAutPianFeriePkObjectKey()))
							.withRel("theDpercAutPianFeriePk"));
			dpercAutPianFerieHDto.add(dpercAutPianFeriePkLink);
		}
		if (dpercAutPianFerieH.getTheDconfigPaPianiFerie() != null) {
			Link dconfigPaPianiFerieLink = convert(linkTo(methodOn(DconfigPaPianiFerieController.class)
					.getByObjectKey(dpercAutPianFerieH.getTheDconfigPaPianiFerieObjectKey()))
							.withRel("theDconfigPaPianiFerie"));
			dpercAutPianFerieHDto.add(dconfigPaPianiFerieLink);
		}

		// CHILDREN LINKS

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dpercAutPianFerieHDto;

	}

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

		return collectionEntities;
	}

}

