using System.Xml.Serialization;
using Model.Stub;

namespace Model;

public class InfoTitle : Title
{
    public Artist Artist { get; set; }

    public string Description
    {
        get => description;

        set
        {
            if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH)
            {
                description = value;
            }
        }
    }

    private string description = Manager.DEFAULT_DESC;

    private List<Artist> feat = new List<Artist>();

    public IEnumerable<Artist> Feat
    {
        get
        {
            return new List<Artist>(feat);
        }
    }

    public Genre Genre { get; set; }

    public InfoTitle(string name, string imageURL, string information, Artist artist, string description, Genre genre) : base(name,imageURL,information)
    {
        Artist = artist;
        Description = description;
        Genre = genre;
    }

    public InfoTitle() : base(Manager.DEFAULT_NAME, Manager.DEFAULT_URL, Manager.DEFAULT_DESC)
    {
        Artist = new Artist(Manager.DEFAULT_NAME);
    }

    public void AddFeat(Artist artist)
    {
        feat.Add(artist);
    }
    public void RemoveFeat(Artist artiste)
    {
        foreach (var item in Feat)
        {
            feat = Feat.Where(item => item != artiste).ToList();
        }
    }

    public override bool Equals(object? obj)
    {
        if (obj is null) return false;
        if (obj.GetType() != typeof(InfoTitle)) return false;
        if (obj is InfoTitle infoTitle && ImageURL == infoTitle.ImageURL) return true;
        else return false;
    }

    public override int GetHashCode()
    {
        return ImageURL.GetHashCode();
    }

    public override string ToString()
    {
        return $"Name : {Name}, ImageUrl : {ImageURL}";
    }
}