package de.nl.moo.assemblers.database;

import de.nl.moo.assemblers.AbstractResourceAssemblerSupport;
import de.nl.moo.controllers.database.EquipmentController;
import de.nl.moo.data.beans.equipments.EquipmentsEquipmentBean;
import de.nl.moo.data.beans.equipments.EquipmentsInstallerBean;
import de.nl.moo.datebase.equipments.Equipment;
import de.nl.moo.responses.database.EquipmentResponse;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;

public class EquipmentResponseAssembler extends AbstractResourceAssemblerSupport<Equipment, EquipmentResponse> {

    public EquipmentResponseAssembler() {
        super(EquipmentController.class, EquipmentResponse.class);
    }

    @Override
    public EquipmentResponse toResource(Equipment entity) {
        EquipmentResponse response = this.instantiateResource(entity);

        EquipmentsEquipmentBean bean = entity.getBean();
        this.invokeName(response, bean);

        String description = bean.getDescription();
        response.setDescription(description);

        EquipmentsInstallerBean installer = entity.getInstaller();
        this.invokeFunction(response, installer);

        int id = bean.getId();
        Link selfLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(EquipmentController.class).get(id)).withSelfRel();
        response.add(selfLink);

        return response;
    }
}
