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

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

@Mapper
public interface MdCatalogsMapper {

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