package com.oguerreiro.resilient.service.mapper;

import com.oguerreiro.resilient.domain.MetadataProperty;
import com.oguerreiro.resilient.domain.OrganizationType;
import com.oguerreiro.resilient.service.dto.MetadataPropertyDTO;
import com.oguerreiro.resilient.service.dto.OrganizationTypeDTO;
import java.util.Set;
import java.util.stream.Collectors;
import org.mapstruct.*;

/**
 * Mapper for the entity {@link OrganizationType} and its DTO {@link OrganizationTypeDTO}.
 */
@Mapper(componentModel = "spring")
public interface OrganizationTypeMapper extends ResilientEntityMapper<OrganizationTypeDTO, OrganizationType> {
    @Mapping(target = "metadataProperties", source = "metadataProperties", qualifiedByName = "metadataPropertyNameSet")
    OrganizationTypeDTO toDto(OrganizationType s);

    @Mapping(target = "removeMetadataProperties", ignore = true)
    OrganizationType toEntity(OrganizationTypeDTO organizationTypeDTO);

    @Named("metadataPropertyName")
    @BeanMapping(ignoreByDefault = true)
    @Mapping(target = "id", source = "id")
    @Mapping(target = "name", source = "name")
    @Mapping(target = "version", source = "version")
    MetadataPropertyDTO toDtoMetadataPropertyName(MetadataProperty metadataProperty);

    @Named("metadataPropertyNameSet")
    default Set<MetadataPropertyDTO> toDtoMetadataPropertyNameSet(Set<MetadataProperty> metadataProperty) {
        return metadataProperty.stream().map(this::toDtoMetadataPropertyName).collect(Collectors.toSet());
    }
}
