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

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

@Mapper
public interface MdColumnsMapper {

    MdColumnsMapper INSTANCE = Mappers.getMapper(MdColumnsMapper.class);

    @Mapping(source = "tableIdFk", target = "tableIdFk.id")

    MdColumns getEntidad(MdColumnsDTO mdColumns);

    @Mapping(target = "tableIdFk", source = "tableIdFk.id")
    MdColumnsDTO getDto(MdColumns mdColumns);

    @AfterMapping
    default void validaNulos(MdColumnsDTO mdColumnsDTO, @MappingTarget MdColumns mdColumns) {
        if (mdColumns.getTableIdFk()!= null && mdColumns.getTableIdFk().getId() == null) {
            mdColumns.setTableIdFk(null);
        }
        
    }
}