using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace AxCopilot.ViewModels;

public class SnippetRowModel : INotifyPropertyChanged
{
	private string _key = "";

	private string _name = "";

	private string _content = "";

	public string Key
	{
		get
		{
			return _key;
		}
		set
		{
			_key = value;
			OnPropertyChanged("Key");
		}
	}

	public string Name
	{
		get
		{
			return _name;
		}
		set
		{
			_name = value;
			OnPropertyChanged("Name");
		}
	}

	public string Content
	{
		get
		{
			return _content;
		}
		set
		{
			_content = value;
			OnPropertyChanged("Content");
		}
	}

	public string Preview => (Content.Length > 50) ? (Content.Substring(0, 47).Replace("\n", " ") + "…") : Content.Replace("\n", " ");

	public event PropertyChangedEventHandler? PropertyChanged;

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