using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Music.Model
{
    public class SongService
    {
        private IArtistRepository _artistRepository;
        private IAlbumRepository _albumRepository;
        private ISongRepository _songRepository;

        public SongService(IArtistRepository artistRepo,
            IAlbumRepository albumRepo,
            ISongRepository songRepo)
        {
            _artistRepository = artistRepo;
            _albumRepository = albumRepo;
            _songRepository = songRepo;
        }

        public Artist GetArtistBy(int id)
        {
            return _artistRepository.FindBy(id);
        }

        public Album GetAlbumBy(int id)
        {
            return _albumRepository.FindBy(id);
        }

        public Song GetSongBy(int id)
        {
            return _songRepository.FindBy(id);
        }

        public IEnumerable<Artist> GetAllArtists()
        {
            return _artistRepository.FindAll();
        }

        public IEnumerable<Album> GetAllAlbums()
        {
            return _albumRepository.FindAll();
        }

        public IEnumerable<Song> GetAllSongs()
        {
            return _songRepository.FindAll();
        }

        public IEnumerable<Album> GetAlbumsBy(Artist artist)
        {
            return _albumRepository.FindAll()
                .Where(album => album.ArtistName == artist.ArtistName);
        }

        public IEnumerable<Album> GetAlbumsBy(int artistId)
        {
            return GetAlbumsBy(_artistRepository.FindBy(artistId));
        }

        public IEnumerable<Song> GetSongsBy(Artist artist)
        {
            return _songRepository.FindAll()
                .Where(song => song.ArtistName == artist.ArtistName);
        }

        public IEnumerable<Song> GetSongsBy(int artistId)
        {
            return GetSongsBy(_artistRepository.FindBy(artistId));
        }

        public IEnumerable<Song> GetSongsOn(Album album)
        {
            return _songRepository.FindAll()
                .Where(song => song.AlbumName == album.AlbumName && song.ArtistName == album.ArtistName);
        }

        public IEnumerable<Song> GetSongsOn(int albumId)
        {
            return GetSongsOn(_albumRepository.FindBy(albumId));
        }
    }
}
