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

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

@Mapper
public interface MdIndexesMapper {

    MdIndexesMapper INSTANCE = Mappers.getMapper(MdIndexesMapper.class);
    @Mapping(source = "tableIdFk", target = "tableIdFk.id")

    MdIndexes getEntidad(MdIndexesDTO mdIndexes);

    @Mapping(target = "tableIdFk", source = "tableIdFk.id")
    MdIndexesDTO getDto(MdIndexes mdIndexes);
    @AfterMapping
    default void validaNulos(MdIndexesDTO mdIndexesDto, @MappingTarget MdIndexes mdIndexes) {
        if (mdIndexes.getTableIdFk()!= null && mdIndexes.getTableIdFk().getId() == null) {
            mdIndexes.setTableIdFk(null);
        }
    }
}