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

namespace Model
{
    public class Title
    {
        public string Name
        {
            get => name;

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

        private string name = Manager.DEFAULT_NAME;

        public string ImageURL
        {
            get => imageURL;

            set
            {
                if (value == null || !value.Contains('.'))
                {
                    value = "none.png";
                    imageURL = value;
                }
                if (value.Contains(' '))
                {
                    imageURL = value.Replace(' ', '_');
                }
                else if (value.Contains('.'))
                {
                    imageURL = value;
                }
            }
        }

        private string imageURL = Manager.DEFAULT_URL;

        public string Information
        {
            get => information;

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

        private string information = Manager.DEFAULT_DESC;

        public Title(string nom, string file_Name, string informations)
        {
            Name = nom;
            ImageURL = file_Name;
            Information = informations;
        }

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

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

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