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

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

@Mapper
public interface MdAdditionalPropertiesMapper {

    MdAdditionalPropertiesMapper INSTANCE = Mappers.getMapper(MdAdditionalPropertiesMapper.class);
    @Mapping(source = "connectionIdFk", target = "connectionIdFk.id")
    MdAdditionalProperties getEntidad(MdAdditionalPropertiesDTO mdAdditionalProperties);

    @Mapping(target = "connectionIdFk", source = "connectionIdFk.id")
    MdAdditionalPropertiesDTO getDto(MdAdditionalProperties mdAdditionalProperties);
    
    @AfterMapping
    default void validaNulos(MdAdditionalPropertiesDTO mdAddtionalPropertiesDto, @MappingTarget MdAdditionalProperties mdAddtionalProperties) {
        if (mdAddtionalProperties.getConnectionIdFk() != null && mdAddtionalProperties.getConnectionIdFk().getId() == null) {
            mdAddtionalProperties.setConnectionIdFk(null);
        }
        
    }
}