package de.thpeetz.kontor.media.services;

import de.thpeetz.kontor.media.data.MediaVideo;
import de.thpeetz.kontor.media.repository.MediaVideoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MediaVideoService {

    private final MediaVideoRepository mediaVideoRepository;

    public MediaVideoService(MediaVideoRepository mediaVideoRepository) {
        this.mediaVideoRepository = mediaVideoRepository;
    }

    public List<MediaVideo> findAllMediaVideos(String stringFilter) {
        if (stringFilter == null || stringFilter.isEmpty()) {
            return mediaVideoRepository.findAll();
        } else {
            return mediaVideoRepository.search(stringFilter);
        }
    }

    public void saveMediaVideo(MediaVideo mediaVideo) {
        if (mediaVideo == null) {
            log.warn("MediaFile is null. Are you sure you have connected your form to the application?");
            return;
        }
        mediaVideoRepository.save(mediaVideo);
    }

    public void deleteMediaVideo(MediaVideo mediaVideo) {
        mediaVideoRepository.delete(mediaVideo);
    }
}
