using System.Collections.ObjectModel;

namespace Model.Stub;

public class StubManager : IDataManager
{
    // Stubs

    public StubAlbum StubAlbum
    {
        get
        {
            return stubAlbum;
        }
    }

    private readonly StubAlbum stubAlbum;

    public StubArtist StubArtist
    {
        get
        {
            return stubArtist;
        }
    }

    private readonly StubArtist stubArtist;

    public StubCustomTitle StubCustomTitle
    {
        get
        {
            return stubCustomTitle;
        }
    }

    private readonly StubCustomTitle stubCustomTitle;

    public StubInfoTitle StubInfoTitle
    {
        get
        {
            return stubInfoTitle;
        }
    }

    private readonly StubInfoTitle stubInfoTitle;

    public StubPlaylist StubPlaylist
    {
        get
        {
            return stubPlaylist;
        }
    }

    private readonly StubPlaylist stubPlaylist;

    public StubManager()
    {
        stubAlbum = new StubAlbum();
        stubArtist = new StubArtist();
        stubCustomTitle = new StubCustomTitle();
        stubInfoTitle = new StubInfoTitle();
        stubPlaylist = new StubPlaylist();
        LoadSerialization();
    }

    public ObservableCollection<Album> GetAlbums()
    {
        return StubAlbum.GetAlbums();   
    }

    public List<Artist> GetArtists()
    {
        return StubArtist.GetArtists();
    }

    public ObservableCollection<Playlist> GetPlaylists()
    {
        return StubPlaylist.GetPlaylists();
    }

    public ObservableCollection<CustomTitle> GetCustomTitles()
    {
        return StubCustomTitle.GetCustomTitles();
    }

    public ObservableCollection<InfoTitle> GetInfoTitles()
    {
        return StubInfoTitle.GetInfoTitles();
    }

    public void AddAlbum(Album album)
    {
        StubAlbum.AddAlbum(album);
    }

    public void AddCustomTitle(CustomTitle title)
    {
        StubCustomTitle.AddCustomTitle(title);
    }

    public void AddInfoTitle(InfoTitle title)
    {
        StubInfoTitle.AddInfoTitle(title);
    }

    public static void AddFeat(InfoTitle infoTitle, Artist artist)
    {
        StubInfoTitle.AddFeat(infoTitle, artist);
    }

    public void AddPlaylist(Playlist playlist)
    {
        StubPlaylist.AddPlaylist(playlist);
    }

    public void AddArtist(Artist artist)
    {
        StubArtist.AddArtist(artist);
    }



    public void RemoveAlbum(Album album)
    {
        StubAlbum.RemoveAlbum(album);
    }

    public void RemoveCustomTitle(CustomTitle title)
    {
        StubCustomTitle.RemoveCustomTitle(title);
    }

    public void RemoveInfoTitle(InfoTitle title)
    {
        StubInfoTitle.RemoveInfoTitle(title);
    }

    public void RemovePlaylist(Playlist playlist)
    {
        StubPlaylist.RemovePlaylist(playlist);
    }

    public void RemoveArtist(Artist artist)
    {
        StubArtist.RemoveArtist(artist);
    }

    public void LoadSerialization()
    {
        StubArtist.AddArtist(new Artist("Imagine Dragons"));
        StubAlbum.AddAlbum(new Album("Mercury Act 2", "image14.png", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", "infos"));
        StubPlaylist.Playlists.First().AddTitle(StubCustomTitle.CustomTitles.First());
        StubInfoTitle.AddInfoTitle(new InfoTitle("Bones", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Symphony", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Sharks", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("I don't like myself", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Blur", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Higher ground", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Crushed", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Take it easy", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Waves", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("I'm happy", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Ferris wheel", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Peace of mind", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Sirens", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Tied", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Younger", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("Continual", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        StubInfoTitle.AddInfoTitle(new InfoTitle("They don't know you like I do", "none.png", "infos", StubArtist.GetArtistByName("Imagine Dragons") ?? new Artist("Imagine Dragons"), "desc", Genre.POP));
        foreach (var infoTitle in StubInfoTitle.InfoTitles)
        {
            switch(infoTitle.Name)
            {
                case "Bones":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Symphony":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Sharks":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "I don't like myself":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Blur":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Higher ground":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Crushed":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Take it easy":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Waves":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "I'm Happy":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Ferris wheel":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Peace of mind":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Sirens":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Tied":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Younger":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "Continual":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                case "They don't know you like I do":
                    StubAlbum.GetAlbumByName("Mercury Act 2")!.AddTitle(infoTitle);
                    break;
                default:
                    break;
            }
        }
    }

    public void SaveSerialization()
    {
        // Doesn't do anything because it's Stubs
    }

    public CustomTitle? GetCustomTitleByUrl(string custom)
    {
        foreach (CustomTitle customTitle in StubCustomTitle.GetCustomTitles())
        {
            if (customTitle.ImageURL == custom)
            {
                return customTitle;
            }
        }
        return null;
    }

    public InfoTitle? GetInfoTitleByName(string name)
    {
        foreach(InfoTitle title in StubInfoTitle.GetInfoTitles())
        {
            if (title.Name == name)
            {
                return title;
            }
        }
        return null;
    }

    public Album? GetAlbumByName(string name)
    {
        foreach(Album album in StubAlbum.GetAlbums())
        {
            if (album.Name == name)
            {
                return album;
            }
        }
        return null;
    }

    public Artist? GetArtistByName(string name)
    {
        foreach(Artist artist in StubArtist.GetArtists())
        {
            if (artist.Name == name)
            {
                return artist;
            }
        }
        return null;
    }

    public void AddAlbums(List<Album> albumsList)
    {
        foreach (Album a in albumsList)
        {
            StubAlbum.AddAlbum(a);
        }
    }

    public void AddArtists(List<Artist> artistsList)
    {
        foreach (Artist a in artistsList)
        {
            StubArtist.AddArtist(a);
        }
    }

    public void AddPlaylists(List<Playlist> playlistsList)
    {
        foreach (Playlist p in playlistsList)
        {
            StubPlaylist.AddPlaylist(p);
        }
    }

    public void AddCustomTitles(List<CustomTitle> customTitlesList)
    {
        foreach (CustomTitle ct in customTitlesList)
        {
            StubCustomTitle.AddCustomTitle(ct);
        }
    }

    public void AddInfoTitles(List<InfoTitle> infoTitlesList)
    {
        foreach (InfoTitle it in infoTitlesList)
        {
            StubInfoTitle.AddInfoTitle(it);
        }
    }

    public Playlist? GetPlaylistByName(string name)
    {
        foreach (Playlist p in StubPlaylist.Playlists)
        {
            if (p.Name == name)
            {
                return p;
            }
        }
        return null;
    }

    public void UpdateCustomTitle(CustomTitle title, string name, string url, string info, string path)
    {
        title.Name = name;
        title.ImageURL = url;
        title.Information = info;
        title.Path = path;
    }

    public void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path)
    {
        CustomTitle? title = GetCustomTitleByUrl(url);
        if (title != null)
        {
            title.Name = name;
            title.ImageURL = newUrl;
            title.Information = info;
            title.Path = path;
        }
    }

    public void UpdateInfoTitle(InfoTitle title, string name, string url, string info, Artist artist, string description, Genre genre)
    {
        title.Name = name;
        title.ImageURL = url;
        title.Information = info;
        title.Artist = artist;
        title.Description = description;
        title.Genre = genre;
    }

    public void UpdateInfoTitleByName(string name, string newUrl, string info, Artist artist, string description, Genre genre)
    {
        InfoTitle? title = GetInfoTitleByName(name);
        if (title != null)
        {
            title.Name = name;
            title.ImageURL = newUrl;
            title.Information = info;
            title.Artist = artist;
            title.Description = description;
            title.Genre = genre;
        }
    }

    public void UpdateInfoTitleByArtistName(InfoTitle title, string name, string url, string info, string artist, string description, Genre genre)
    {
        title.Name = name;
        title.ImageURL = url;
        title.Information = info;
        Artist? artist2 = GetArtistByName(artist);
        if (artist2 != null)
        {
            title.Artist = artist2;
        }
        title.Description = description;
        title.Genre = genre;
    }

    public void UpdateInfoTitleByNameByArtistName(string name, string newUrl, string info, string artist, string description, Genre genre)
    {
        InfoTitle? title = GetInfoTitleByName(name);
        if (title != null)
        {
            title.Name = name;
            title.ImageURL = newUrl;
            title.Information = info;
            Artist? artist2 = GetArtistByName(artist);
            if (artist2 != null)
            {
                title.Artist = artist2;
            }
            title.Description = description;
            title.Genre = genre;
        }
    }

    public void UpdateAlbum(Album album, string name, string url, Artist artist, string description, string info)
    {
        album.Name = name;
        album.ImageURL = url;
        album.Artist = artist;
        album.Description = description;
        album.Information = info;
    }

    public void UpdateAlbumByName(string name, string newUrl, Artist artist, string description, string info)
    {
        Album? album = GetAlbumByName(name);
        if (album != null)
        {
            album.Name = name;
            album.ImageURL = newUrl;
            album.Artist = artist;
            album.Description = description;
            album.Information = info;
        }
    }

    public void UpdateAlbumByArtistName(Album album, string name, string url, string artist, string description, string info)
    {
        album.Name = name;
        album.ImageURL = url;
        Artist? artist2 = GetArtistByName(artist);
        if (artist2 != null)
        {
            album.Artist = artist2;
        }
        album.Description = description;
        album.Information = info;
    }

    public void UpdateAlbumByNameByArtistName(string name, string newUrl, string artist, string description, string info)
    {
        Album? album = GetAlbumByName(name);
        if (album != null)
        {
            album.Name = name;
            album.ImageURL = newUrl;
            Artist? artist2 = GetArtistByName(artist);
            if (artist2 != null)
            {
                album.Artist = artist2;
            }
            album.Description = description;
            album.Information = info;
        }
    }

    public void UpdatePlaylist(Playlist playlist, string name, string description, string url)
    {
        playlist.Name = name;
        playlist.Description = description;
        playlist.ImageURL = url;
    }

    public void UpdatePlaylistByName(string name, string description, string newUrl)
    {
        Playlist? playlist = GetPlaylistByName(name);
        if (playlist != null)
        {
            playlist.Name = name;
            playlist.Description = description;
            playlist.ImageURL = newUrl;
        }
    }

    public void UpdateArtist(Artist artist, string name)
    {
        artist.Name = name;
    }

    public void UpdateArtistByName(string name, string newName)
    {
        Artist? artist = GetArtistByName(newName);
        if (artist != null)
        {
            artist.Name = newName;
        }
    }

    public void RemoveAlbums(List<Album> albumsList)
    {
        foreach (Album album in albumsList)
        {
            StubAlbum.RemoveAlbum(album);
        }
    }

    public void RemoveArtists(List<Artist> artistsList)
    {
        foreach (Artist artist in artistsList)
        {
            StubArtist.RemoveArtist(artist);
        }
    }

    public void RemovePlaylists(List<Playlist> playlistsList)
    {
        foreach (Playlist playlist in playlistsList)
        {
            StubPlaylist.RemovePlaylist(playlist);
        }
    }

    public void RemoveCustomTitles(List<CustomTitle> customTitlesList)
    {
        foreach (CustomTitle customTitle in customTitlesList)
        {
            StubCustomTitle.RemoveCustomTitle(customTitle);
        }
    }

    public void RemoveInfoTitles(List<InfoTitle> infoTitlesList)
    {
        foreach (InfoTitle infoTitle in infoTitlesList)
        {
            StubInfoTitle.RemoveInfoTitle(infoTitle);
        }
    }

    public bool ExistsPlaylist(Playlist playlist)
    {
        foreach (Playlist p in StubPlaylist.Playlists)
        {
            if (p == playlist)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsPlaylistByName(string name)
    {
        foreach (Playlist p in StubPlaylist.Playlists)
        {
            if (p.Name == name)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsAlbum(Album album)
    {
        foreach (Album a in StubAlbum.Albums)
        {
            if (a == album)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsAlbumByName(string name)
    {
        foreach (Album a in StubAlbum.Albums)
        {
            if (a.Name == name)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsArtist(Artist artist)
    {
        foreach (Artist a in StubArtist.Artists)
        {
            if (a == artist)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsArtistByName(string name)
    {
        foreach (Artist a in StubArtist.Artists)
        {
            if (a.Name == name)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsCustomTitle(CustomTitle title)
    {
        foreach (CustomTitle ct in StubCustomTitle.CustomTitles)
        {
            if (title == ct)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsCustomTitleByName(string name)
    {
        foreach (CustomTitle ct in StubCustomTitle.CustomTitles)
        {
            if (ct.Name == name)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsInfoTitle(InfoTitle title)
    {
        foreach (InfoTitle it in StubInfoTitle.InfoTitles)
        {
            if (it == title)
            {
                return true;
            }
        }
        return false;
    }

    public bool ExistsInfoTitleByName(string name)
    {
        foreach (InfoTitle it in StubInfoTitle.InfoTitles)
        {
            if (it.Name == name)
            {
                return true;
            }
        }
        return false;
    }
}
