package com.example.video_downloader.services;

import com.example.video_downloader.dto.SaveNewPlaylistRequest;
import com.example.video_downloader.entity.Playlist;
import com.example.video_downloader.entity.StatusEnum;
import com.example.video_downloader.repositories.PlaylistRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.InvalidParameterException;
import java.util.List;

@Service
public class PlaylistService {

    @Autowired
    private PlaylistRepository playlistRepository;

    public Playlist saveNewPlaylist(SaveNewPlaylistRequest request){
        if(!request.getUrl().contains("list")) throw new InvalidParameterException();
        Playlist playlist = new Playlist();
        playlist.setStatus(StatusEnum.NEW);
        playlist.setPlaylistName(request.getPlaylistName());
        playlist.setUrl(request.getUrl());
        playlistRepository.save(playlist);
        return playlist;
    }

    public List<Playlist> getAllPlaylists(){
        return playlistRepository.findAll();
    }
}
