using Model.Stub;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Xml.Serialization;

namespace Model;

public class Title
{

    public event PropertyChangedEventHandler? PropertyChanged;

    protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    public string Name
    {
        get => name;

        set
        {
            if (string.IsNullOrWhiteSpace(value) || value.Length > Manager.MAX_NAME_LENGTH)
            {
                value = "IncorrectName";
            }
            name = value;
            OnPropertyChanged();
        }
    }

    private string name = Manager.DEFAULT_NAME;

    public string ImageURL
    {
        get => imageURL;

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

    private string imageURL = Manager.DEFAULT_URL;

    public string Information
    {
        get => information;

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

    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 && Name == title.Name) return true;
        else return false;
    }

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

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