package io.delphiplatform.api.v3.search.processing;

import org.springframework.stereotype.Service;

import java.util.stream.Stream;

import fr.xebia.extras.selma.Selma;
import io.delphiplatform.api.v3.model.ArtistSimple;
import io.delphiplatform.api.v3.model.mapper.ArtistDocumentMapper;
import io.delphiplatform.api.v3.model.service.ImageService;
import io.delphiplatform.api.v3.search.entity.ArtistDocumentEntity;


@Service
public class ArtistDocumentConverter {

    private final ArtistDocumentMapper artistDocumentMapper;
    private final ImageService imageService;

    public ArtistDocumentConverter(ImageService imageService) {
        this.imageService = imageService;
        this.artistDocumentMapper = Selma.builder(ArtistDocumentMapper.class).build();
    }

    public Stream<ArtistSimple> convert(Stream<ArtistDocumentEntity> artistDocuments) {
        return artistDocuments.map(a -> artistDocumentMapper().toArtistSimple(a).image(imageService.resolveImage(a)));
    }

    private ArtistDocumentMapper artistDocumentMapper() {
        return artistDocumentMapper;
    }

}
