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 MetadataProperty} and its DTO {@link MetadataPropertyDTO}.
 */
@Mapper(componentModel = "spring")
public interface MetadataPropertyMapper extends ResilientEntityMapper<MetadataPropertyDTO, MetadataProperty> {
    @Mapping(target = "organizationTypes", source = "organizationTypes", qualifiedByName = "organizationTypeNameSet")
    MetadataPropertyDTO toDto(MetadataProperty s);

    @Mapping(target = "organizationTypes", ignore = true)
    @Mapping(target = "removeOrganizationType", ignore = true)
    MetadataProperty toEntity(MetadataPropertyDTO metadataPropertyDTO);

    @Named("organizationTypeName")
    @BeanMapping(ignoreByDefault = true)
    @Mapping(target = "id", source = "id")
    @Mapping(target = "name", source = "name")
    OrganizationTypeDTO toDtoOrganizationTypeName(OrganizationType organizationType);

    @Named("organizationTypeNameSet")
    default Set<OrganizationTypeDTO> toDtoOrganizationTypeNameSet(Set<OrganizationType> organizationType) {
        return organizationType.stream().map(this::toDtoOrganizationTypeName).collect(Collectors.toSet());
    }
}
