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.DstatiRichApprovPfController;
import it.micegroup.gestioneferie.pianificazioneferie.dto.DstatiRichApprovPfDto;
import it.micegroup.gestioneferie.pianificazioneferie.entity.DstatiRichApprovPf;

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

@Component
public class DstatiRichApprovPfModelAssembler
		extends BaseModelAssembler<DstatiRichApprovPf, DstatiRichApprovPfDto, DstatiRichApprovPfController> {

	@Override
	public DstatiRichApprovPfDto toModel(DstatiRichApprovPf dstatiRichApprovPf) {
		DstatiRichApprovPfDto dstatiRichApprovPfDto = map(dstatiRichApprovPf, DstatiRichApprovPfDto.class,
				DstatiRichApprovPfController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DstatiRichApprovPfController.class).getByObjectKey(dstatiRichApprovPf.getObjectKey()))
						.withSelfRel());
		dstatiRichApprovPfDto.add(selfLink);

		// PARENT LINKS

		// CHILDREN LINKS
		if (dstatiRichApprovPf.getTheDrichiesteApprovazPf() != null) {
			Link drichiesteApprovazPfLink = convert(linkTo(methodOn(DrichiesteApprovazPfController.class)
					.findByDstatiRichApprovPf(dstatiRichApprovPf.getObjectKey(), null))
							.withRel("theDrichiesteApprovazPf"));
			dstatiRichApprovPfDto.add(drichiesteApprovazPfLink);
		}

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dstatiRichApprovPfDto;

	}

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

		return collectionEntities;
	}

}

