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

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

@Mapper
public interface MdFileArtifactsMapper {

    MdFileArtifactsMapper INSTANCE = Mappers.getMapper(MdFileArtifactsMapper.class);
    @Mapping(source = "applicationfilesId", target = "applicationfilesId.id")
    MdFileArtifacts getEntidad(MdFileArtifactsDTO mdFileArtifacts);
    
    @Mapping(target = "applicationfilesId", source = "applicationfilesId.id")
    MdFileArtifactsDTO getDto(MdFileArtifacts mdFileArtifacts);
    
    @AfterMapping
    default void validaNulos(MdFileArtifactsDTO mdDerivativesDto, @MappingTarget MdFileArtifacts mdDerivatives) {
        if (mdDerivatives.getApplicationfilesId()!= null && mdDerivatives.getApplicationfilesId().getId() == null) {
            mdDerivatives.setApplicationfilesId(null);
        }
    }
}