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.DconfigPaPianiFerieController;
import it.micegroup.gestioneferie.configurazionepf.dto.DconfigPaPianiFerieDto;
import it.micegroup.gestioneferie.configurazionepf.entity.DconfigPaPianiFerie;

import it.micegroup.gestioneferie.configurazionepf.controller.DpercAutPianFerieHController;
import it.micegroup.gestioneferie.configurazionepf.controller.DconfigPaPfUoHController;

@Component
public class DconfigPaPianiFerieModelAssembler
		extends BaseModelAssembler<DconfigPaPianiFerie, DconfigPaPianiFerieDto, DconfigPaPianiFerieController> {

	@Override
	public DconfigPaPianiFerieDto toModel(DconfigPaPianiFerie dconfigPaPianiFerie) {
		DconfigPaPianiFerieDto dconfigPaPianiFerieDto = map(dconfigPaPianiFerie, DconfigPaPianiFerieDto.class,
				DconfigPaPianiFerieController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DconfigPaPianiFerieController.class).getByObjectKey(dconfigPaPianiFerie.getObjectKey()))
						.withSelfRel());
		dconfigPaPianiFerieDto.add(selfLink);

		// PARENT LINKS

		// CHILDREN LINKS
		if (dconfigPaPianiFerie.getTheDpercAutPianFerieH() != null) {
			Link dpercAutPianFerieHLink = convert(linkTo(methodOn(DpercAutPianFerieHController.class)
					.findByDconfigPaPianiFerie(dconfigPaPianiFerie.getObjectKey(), null))
							.withRel("theDpercAutPianFerieH"));
			dconfigPaPianiFerieDto.add(dpercAutPianFerieHLink);
		}
		if (dconfigPaPianiFerie.getTheDconfigPaPfUoH() != null) {
			Link dconfigPaPfUoHLink = convert(linkTo(methodOn(DconfigPaPfUoHController.class)
					.findByDconfigPaPianiFerie(dconfigPaPianiFerie.getObjectKey(), null)).withRel("theDconfigPaPfUoH"));
			dconfigPaPianiFerieDto.add(dconfigPaPfUoHLink);
		}

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dconfigPaPianiFerieDto;

	}

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

		return collectionEntities;
	}

}

