using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Model.Stub;

public class Manager
{ 
    public readonly static int MAX_NAME_LENGTH = 75;

    public readonly static int MAX_DESCRIPTION_LENGTH = 500;

    public readonly static string DEFAULT_NAME = "Unknown";

    public readonly static string DEFAULT_URL = "none.png";

    public readonly static string DEFAULT_DESC = "";

    public IDataManager DataManager { get; set; }

    private ObservableCollection<Album> albums;

    public ObservableCollection<Album> Albums
    {
        get
        {
            return new ObservableCollection<Album>(albums);
        }
    }

    private ObservableCollection<CustomTitle> customTitles;

    public ObservableCollection<CustomTitle> CustomTitles
    {
        get
        {
            return new ObservableCollection<CustomTitle>(customTitles);
        }
    }

    private ObservableCollection<InfoTitle> infoTitles;

    public ObservableCollection<InfoTitle> InfoTitles
    {
        get
        {
            return new ObservableCollection<InfoTitle>(infoTitles);
        }
    }

    private ObservableCollection<Playlist> playlists;

    public ObservableCollection<Playlist> Playlists
    {
        get
        {
            return new ObservableCollection<Playlist>(playlists);
        }
    }

    private List<Artist> artists;

    public IEnumerable<Artist> Artists
    {
        get
        {
            return new List<Artist>(artists);
        }
    }

    private Playlist? currentPlaylist;

    public Playlist? CurrentPlaylist
    {
        get => currentPlaylist;
        set
        {
            currentPlaylist = value;
        }
    }

    public Manager(IDataManager dataManager)
    {
        DataManager = dataManager;

        albums = DataManager.GetAlbums();
        customTitles = DataManager.GetCustomTitles();
        infoTitles = DataManager.GetInfoTitles();
        playlists = DataManager.GetPlaylists();
        artists = DataManager.GetArtists();

        currentPlaylist = playlists.FirstOrDefault();
    }

    public void AddAlbum(Album album)
    {
        if (GetAlbumByName(album.Name) != null) return;
        DataManager.AddAlbum(album);
        albums = DataManager.GetAlbums();
    }

    public void AddCustomTitle(CustomTitle title)
    {
        if (GetInfoTitleByName(title.Name) != null) return;
        DataManager.AddCustomTitle(title);
        customTitles = DataManager.GetCustomTitles();
    }

    public void AddInfoTitle(InfoTitle title)
    {
        if (GetInfoTitleByName(title.Name) != null) return;
        DataManager.AddInfoTitle(title);
        infoTitles = DataManager.GetInfoTitles();
    }

    public void AddPlaylist(Playlist playlist)
    {
        if (GetPlaylistByName(playlist.Name) != null) return;
        DataManager.AddPlaylist(playlist);
        playlists = DataManager.GetPlaylists();
    }

    public void AddArtist(Artist artist)
    {
        if (GetArtistByName(artist.Name) != null) return;
        DataManager.AddArtist(artist);
        artists = DataManager.GetArtists();
    }

    public void RemoveAlbum(Album album)
    {
        DataManager.RemoveAlbum(album);
        albums = DataManager.GetAlbums();
    }

    public void RemoveCustomTitle(CustomTitle title)
    {
        DataManager.RemoveCustomTitle(title);
        customTitles = DataManager.GetCustomTitles();
    }

    public void RemoveInfoTitle(InfoTitle title)
    {
        DataManager.RemoveInfoTitle(title);
        infoTitles = DataManager.GetInfoTitles();
    }

    public void RemovePlaylist(Playlist playlist)
    {
        DataManager.RemovePlaylist(playlist);
        playlists = DataManager.GetPlaylists();
    }

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

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

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

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

    public IEnumerable<Artist> GetArtists()
    {
        return DataManager.GetArtists();
    }

    public void LoadSerialization()
    {
        DataManager.LoadSerialization();
    }

    public void SaveSerialization()
    {
        DataManager.SaveSerialization();
    }

    public Playlist? GetPlaylistByName(string name)
    {
        return DataManager.GetPlaylistByName(name);
    }

    public Artist? GetArtistByName(string name)
    {
        return DataManager.GetArtistByName(name);
    }

    public CustomTitle? GetCustomTitleByUrl(string url)
    {
        return DataManager.GetCustomTitleByUrl(url);
    }

    public InfoTitle? GetInfoTitleByName(string name)
    {
        return DataManager.GetInfoTitleByName(name);
    }

    public Album? GetAlbumByName(string name)
    {
        return DataManager.GetAlbumByName(name);
    }

}
