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

import com.qsoft.rs.sincoar.dto.MdConstraintsDTO;
import com.qsoft.rs.sincoar.model.MdDerivatives;
import com.qsoft.rs.sincoar.dto.MdDerivativesDTO;
import com.qsoft.rs.sincoar.model.MdConstraints;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

@Mapper
public interface MdDerivativesMapper {

    MdDerivativesMapper INSTANCE = Mappers.getMapper(MdDerivativesMapper.class);
    @Mapping(source = "derivedConnectionIdFk", target = "derivedConnectionIdFk.id")
    MdDerivatives getEntidad(MdDerivativesDTO mdDerivatives);

    @Mapping(target = "derivedConnectionIdFk", source = "derivedConnectionIdFk.id")
    MdDerivativesDTO getDto(MdDerivatives mdDerivatives);

     @AfterMapping
    default void validaNulos(MdDerivativesDTO mdDerivativesDto, @MappingTarget MdDerivatives mdDerivatives) {
        if (mdDerivatives.getDerivedConnectionIdFk()!= null && mdDerivatives.getDerivedConnectionIdFk().getId() == null) {
            mdDerivatives.setDerivedConnectionIdFk(null);
        }
    }
}