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.DstatiPianificFerieController;
import it.micegroup.gestioneferie.pianificazioneferie.dto.DstatiPianificFerieDto;
import it.micegroup.gestioneferie.pianificazioneferie.entity.DstatiPianificFerie;

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

@Component
public class DstatiPianificFerieModelAssembler
		extends BaseModelAssembler<DstatiPianificFerie, DstatiPianificFerieDto, DstatiPianificFerieController> {

	@Override
	public DstatiPianificFerieDto toModel(DstatiPianificFerie dstatiPianificFerie) {
		DstatiPianificFerieDto dstatiPianificFerieDto = map(dstatiPianificFerie, DstatiPianificFerieDto.class,
				DstatiPianificFerieController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DstatiPianificFerieController.class).getByObjectKey(dstatiPianificFerie.getObjectKey()))
						.withSelfRel());
		dstatiPianificFerieDto.add(selfLink);

		// PARENT LINKS

		// CHILDREN LINKS
		if (dstatiPianificFerie.getTheDpianificFerieAmmto() != null) {
			Link dpianificFerieAmmtoLink = convert(linkTo(methodOn(DpianificFerieAmmtoController.class)
					.findByDstatiPianificFerie(dstatiPianificFerie.getObjectKey(), null))
							.withRel("theDpianificFerieAmmto"));
			dstatiPianificFerieDto.add(dpianificFerieAmmtoLink);
		}

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dstatiPianificFerieDto;

	}

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

		return collectionEntities;
	}

}

