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.DrichiesteApprovazPfController;
import it.micegroup.gestioneferie.pianificazioneferie.dto.DrichiesteApprovazPfDto;
import it.micegroup.gestioneferie.pianificazioneferie.entity.DrichiesteApprovazPf;

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

@Component
public class DrichiesteApprovazPfModelAssembler
		extends BaseModelAssembler<DrichiesteApprovazPf, DrichiesteApprovazPfDto, DrichiesteApprovazPfController> {

	@Override
	public DrichiesteApprovazPfDto toModel(DrichiesteApprovazPf drichiesteApprovazPf) {
		DrichiesteApprovazPfDto drichiesteApprovazPfDto = map(drichiesteApprovazPf, DrichiesteApprovazPfDto.class,
				DrichiesteApprovazPfController.class);

		// SELF LINK
		Link selfLink = convert(linkTo(
				methodOn(DrichiesteApprovazPfController.class).getByObjectKey(drichiesteApprovazPf.getObjectKey()))
						.withSelfRel());
		drichiesteApprovazPfDto.add(selfLink);

		// PARENT LINKS
		if (drichiesteApprovazPf.getTheDstatiRichApprovPf() != null) {
			Link dstatiRichApprovPfLink = convert(linkTo(methodOn(DstatiRichApprovPfController.class)
					.getByObjectKey(drichiesteApprovazPf.getTheDstatiRichApprovPfObjectKey()))
							.withRel("theDstatiRichApprovPf"));
			drichiesteApprovazPfDto.add(dstatiRichApprovPfLink);
		}
		if (drichiesteApprovazPf.getTheDpianiFerie() != null) {
			Link dpianiFerieLink = convert(linkTo(methodOn(DpianiFerieController.class)
					.getByObjectKey(drichiesteApprovazPf.getTheDpianiFerieObjectKey())).withRel("theDpianiFerie"));
			drichiesteApprovazPfDto.add(dpianiFerieLink);
		}

		// CHILDREN LINKS

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return drichiesteApprovazPfDto;

	}

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

		return collectionEntities;
	}

}

