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

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

@Mapper
public interface MdApplicationsMapper {

    MdApplicationsMapper INSTANCE = Mappers.getMapper(MdApplicationsMapper.class);
    @Mapping(source = "connectionIdFk", target = "connectionIdFk.id")
    MdApplications getEntidad(MdApplicationsDTO mdApplications);
    
    @Mapping(target = "connectionIdFk", source = "connectionIdFk.id")
    MdApplicationsDTO getDto(MdApplications mdApplications);
    
    @AfterMapping
    default void validaNulos(MdApplicationsDTO mdApplicationsDto, @MappingTarget MdApplications mdApplications) {
        if (mdApplications.getConnectionIdFk()!= null && mdApplications.getConnectionIdFk().getId() == null) {
            mdApplications.setConnectionIdFk(null);
        }
        
    }
    
}