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

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

@Mapper
public interface MdGroupsMapper {

    MdGroupsMapper INSTANCE = Mappers.getMapper(MdGroupsMapper.class);
    @Mapping(source = "schemaIdFk", target = "schemaIdFk.id")
    MdGroups getEntidad(MdGroupsDTO mdGroups);
    @Mapping(target = "schemaIdFk", source = "schemaIdFk.id")
    MdGroupsDTO getDto(MdGroups mdGroups);

    @AfterMapping
    default void validaNulos(MdGroupsDTO mdGroupsDTO, @MappingTarget MdGroups mdGroups) {
        if (mdGroups.getSchemaIdFk()!= null && mdGroups.getSchemaIdFk().getId() == null) {
            mdGroups.setSchemaIdFk(null);
        }

    }
}