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

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

@Mapper
public interface MdConstraintsMapper {

    MdConstraintsMapper INSTANCE = Mappers.getMapper(MdConstraintsMapper.class);
    @Mapping(source = "tableIdFk", target = "tableIdFk.id")
    MdConstraints getEntidad(MdConstraintsDTO mdConstraints);
    
    @Mapping(target = "tableIdFk", source = "tableIdFk.id")
    MdConstraintsDTO getDto(MdConstraints mdConstraints);
    
    @AfterMapping
    default void validaNulos(MdConstraintsDTO mdConstraintsDTO, @MappingTarget MdConstraints mdConstraints) {
        if (mdConstraints.getTableIdFk()!= null && mdConstraints.getTableIdFk().getId() == null) {
            mdConstraints.setTableIdFk(null);
        }
        
    }

}