using System;
using Avalonia.Controls;
using System.Threading.Tasks;

namespace PortfolioManager.ViewModels
{
    public interface ICloseableDialog
    {
        public Task Close();
    }

    public abstract class DialogViewModelBase : ModelBase, ICloseableDialog, IDisposable
    {
        public DialogViewModelBase(Window dialogWindow)
        {
            DialogWindow = dialogWindow;
        }

        public virtual async Task Close()
        {
            Dispose();
            await Task.FromResult(true);
        }

        public void Dispose()
        {
            if (null == DialogWindow)
            {
                return;
            }
            DialogWindow.Hide();    // !!Important ARM64
            DialogWindow.Close();
            DialogWindow = null;
        }

        public bool IsSuccess { get; set; } = false;

        protected Window DialogWindow { get; private set; }
    }
}
