using CommunityToolkit.Mvvm.ComponentModel;

namespace VisionBuilder.UI.Common.ViewModel.Classes;

public enum EButtonType
{
    Click,
    Toggle
}

public partial class ButtonDefinition : ObservableObject
{
    public string Key { get; }
    public string Title { get; }
    public EButtonType Type { get; }

    [ObservableProperty]
    private bool _isVisible = true;

    [ObservableProperty]
    private bool _isToggled;

    private readonly Action? _clickCallback;
    private readonly Action<bool>? _toggleCallback;

    public ButtonDefinition(string key, string title, Action clickCallback)
    {
        Key = key;
        Title = title;
        Type = EButtonType.Click;
        _clickCallback = clickCallback;
    }

    public ButtonDefinition(string key, string title, Action<bool> toggleCallback, bool initialState = false)
    {
        Key = key;
        Title = title;
        Type = EButtonType.Toggle;
        _toggleCallback = toggleCallback;
        _isToggled = initialState;
    }

    public void Execute()
    {
        if (Type == EButtonType.Click)
        {
            _clickCallback?.Invoke();
        }
        else
        {
            IsToggled = !IsToggled;
            _toggleCallback?.Invoke(IsToggled);
        }
    }
}
