using UnityEngine;
using UnityEngine.UIElements;
using System.ComponentModel;
using Unity.Properties;
using UnityEngine.InputSystem;
using Random = UnityEngine.Random;

// Data model that powers the UI.
// In this model there are property fields that we will bind to visual elements
// Each #region is specified for the visual emenet type in the tutorial
public class MyDataModel : INotifyPropertyChanged
{

#region TextField Example
    // Property fields for the TextField example
    // Use the DontCreateProperty on the private var to keep it isolated
    [DontCreateProperty]
    private string myText;

    // It is considered best practice to use the public param as the property with a getter and setter
    // so that you can perform other functions such as validation or as in this example, raise an event
    [CreateProperty]
    public string MyText
    {
        // Get just returns the value
        get => myText;
        // Set saves the new value and raises an event to alert subscribers of the change
        set
        {
            if (myText != value)
            {
                myText = value;
                OnPropertyChanged(nameof(MyText));
            }
        }
    }
#endregion





    public event PropertyChangedEventHandler PropertyChanged;

    // This is a helper function to notify the UI that a property has changed
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}