package com.oguerreiro.resilient.service.mapper;

import java.util.Set;
import java.util.stream.Collectors;

import org.mapstruct.BeanMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import com.oguerreiro.resilient.domain.VariableClass;
import com.oguerreiro.resilient.domain.VariableClassType;
import com.oguerreiro.resilient.service.dto.VariableClassDTO;
import com.oguerreiro.resilient.service.dto.VariableClassTypeDTO;

/**
 * Mapper for the entity {@link VariableClassType} and its DTO {@link VariableClassTypeDTO}.
 */
@Mapper(componentModel = "spring")
public interface VariableClassTypeMapper extends ResilientEntityMapper<VariableClassTypeDTO, VariableClassType> {
    @Mapping(target = "variableClasses", source = "variableClasses", qualifiedByName = "variableClassNameSet")
    VariableClassTypeDTO toDto(VariableClassType s);
    
    @Mapping(target = "removeVariableClass", ignore = true)
    VariableClassType toEntity(VariableClassTypeDTO variableClassTypeDTO);
    
    @Named("variableClassPropertyName")
    @BeanMapping(ignoreByDefault = true)
    @Mapping(target = "id", source = "id")
    @Mapping(target = "code", source = "code")
    @Mapping(target = "name", source = "name")
    @Mapping(target = "version", source = "version")
    VariableClassDTO toDtoVariableClassPropertyName(VariableClass variableClass);
    
    @Named("variableClassNameSet")
    default Set<VariableClassDTO> toDtoVariableClassPropertyNameSet(Set<VariableClass> variableClass) {
        return variableClass.stream().map(this::toDtoVariableClassPropertyName).collect(Collectors.toSet());
    }
}
