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

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

@Mapper
public interface MdIndexDetailsMapper {

    MdIndexDetailsMapper INSTANCE = Mappers.getMapper(MdIndexDetailsMapper.class);
    @Mapping(source = "columnIdFk", target = "columnIdFk.id")
    @Mapping(source = "indexIdFk", target = "indexIdFk.id")
    MdIndexDetails getEntidad(MdIndexDetailsDTO mdIndexDetails);
    
    @Mapping(target = "columnIdFk", source = "columnIdFk.id")
    @Mapping(target = "indexIdFk", source = "indexIdFk.id")
    MdIndexDetailsDTO getDto(MdIndexDetails mdIndexDetails);
    
    @AfterMapping
    default void validaNulos(MdIndexDetailsDTO mdGroupsDTO, @MappingTarget MdIndexDetails mdGroups) {
        if (mdGroups.getColumnIdFk()!= null && mdGroups.getColumnIdFk().getId() == null) {
            mdGroups.setColumnIdFk(null);
        }
        if (mdGroups.getIndexIdFk()!= null && mdGroups.getIndexIdFk().getId() == null) {
            mdGroups.setIndexIdFk(null);
        }

    }
}