package com.iqser.red.service.persistence.service.v1.api.shared.mongo.service;

import java.util.List;
import java.util.Optional;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Service;

import com.iqser.red.service.persistence.service.v1.api.shared.mongo.document.ImageDocument;
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.repository.ImageDocumentRepository;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class ImageMongoService {

    private MongoOperations mongoOperations;
    private final ImageDocumentRepository imageDocumentRepository;


    public ImageMongoService(MongoOperations mongoOperations, ImageDocumentRepository imageDocumentRepository) {

        this.mongoOperations = mongoOperations;

        this.imageDocumentRepository = imageDocumentRepository;
    }


    public ImageDocument findById(String imageId) {

        Optional<ImageDocument> image = this.imageDocumentRepository.findById(imageId);
        if (image.isPresent()) {
            return image.get();
        }
        return null;
    }


    public List<ImageDocument> findAll() {

        return this.imageDocumentRepository.findAll();
    }


    public void saveImages(List<ImageDocument> imageDocuments) {

        imageDocumentRepository.saveAll(imageDocuments);
    }

}
