package it.micegroup.gestioneferie.pianificazioneferie.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.pianificazioneferie.controller.DstatiPianoFerieController;
import it.micegroup.gestioneferie.pianificazioneferie.dto.DstatiPianoFerieDto;
import it.micegroup.gestioneferie.pianificazioneferie.entity.DstatiPianoFerie;

import it.micegroup.gestioneferie.pianificazioneferie.controller.DpianiFerieController;

@Component
public class DstatiPianoFerieModelAssembler
		extends BaseModelAssembler<DstatiPianoFerie, DstatiPianoFerieDto, DstatiPianoFerieController> {

	@Override
	public DstatiPianoFerieDto toModel(DstatiPianoFerie dstatiPianoFerie) {
		DstatiPianoFerieDto dstatiPianoFerieDto = map(dstatiPianoFerie, DstatiPianoFerieDto.class,
				DstatiPianoFerieController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DstatiPianoFerieController.class).getByObjectKey(dstatiPianoFerie.getObjectKey()))
						.withSelfRel());
		dstatiPianoFerieDto.add(selfLink);

		// PARENT LINKS

		// CHILDREN LINKS
		if (dstatiPianoFerie.getTheDpianiFerie() != null) {
			Link dpianiFerieLink = convert(linkTo(
					methodOn(DpianiFerieController.class).findByDstatiPianoFerie(dstatiPianoFerie.getObjectKey(), null))
							.withRel("theDpianiFerie"));
			dstatiPianoFerieDto.add(dpianiFerieLink);
		}

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dstatiPianoFerieDto;

	}

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

		return collectionEntities;
	}

}

