package com.qsoft.rs.sincoar.dominio.mapper;

import com.qsoft.rs.sincoar.model.MdConnections;
import com.qsoft.rs.sincoar.dto.MdConnectionsDTO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

@Mapper
public interface MdConnectionsMapper {

    MdConnectionsMapper INSTANCE = Mappers.getMapper(MdConnectionsMapper.class);
    @Mapping(source = "projectIdFk", target = "projectIdFk.id")
    MdConnections getEntidad(MdConnectionsDTO mdConnections);
    
    @Mapping(target = "projectIdFk", source = "projectIdFk.id")
    MdConnectionsDTO getDto(MdConnections mdConnections);

    @AfterMapping
    default void validaNulos(MdConnectionsDTO mdConnectionsDto, @MappingTarget MdConnections mdConnections) {
        if (mdConnections.getProjectIdFk()!= null && mdConnections.getProjectIdFk().getId() == null) {
            mdConnections.setProjectIdFk(null);
        }
        
    }
}