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.DregolePianiFeriePkController;
import it.micegroup.gestioneferie.configurazionepf.dto.DregolePianiFeriePkDto;
import it.micegroup.gestioneferie.configurazionepf.entity.DregolePianiFeriePk;

import it.micegroup.gestioneferie.configurazionepf.controller.DregolePianiFerieHController;

@Component
public class DregolePianiFeriePkModelAssembler
		extends BaseModelAssembler<DregolePianiFeriePk, DregolePianiFeriePkDto, DregolePianiFeriePkController> {

	@Override
	public DregolePianiFeriePkDto toModel(DregolePianiFeriePk dregolePianiFeriePk) {
		DregolePianiFeriePkDto dregolePianiFeriePkDto = map(dregolePianiFeriePk, DregolePianiFeriePkDto.class,
				DregolePianiFeriePkController.class);

		// SELF LINK
		Link selfLink = convert(
				linkTo(methodOn(DregolePianiFeriePkController.class).getByObjectKey(dregolePianiFeriePk.getObjectKey()))
						.withSelfRel());
		dregolePianiFeriePkDto.add(selfLink);

		// PARENT LINKS

		// CHILDREN LINKS
		if (dregolePianiFeriePk.getTheDregolePianiFerieH() != null) {
			Link dregolePianiFerieHLink = convert(linkTo(methodOn(DregolePianiFerieHController.class)
					.findByDregolePianiFeriePk(dregolePianiFeriePk.getObjectKey(), null))
							.withRel("theDregolePianiFerieH"));
			dregolePianiFeriePkDto.add(dregolePianiFerieHLink);
		}

		// PARENTS LINKS FOR IMPORTED MS

		// CHILDREN LINKS FOR IMPORTED MS

		return dregolePianiFeriePkDto;

	}

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

		return collectionEntities;
	}

}

