using System;
using System.Collections.Generic;
using Code.Domain;
using UniRx;

namespace Code.InterfaceAdapters.MainMenu
{
    public class MainMenuController : IDisposable
    {
        private readonly MainMenuViewModel _model;
        private readonly LoginRequester _loginRequester;
        private List<IDisposable> _disposables;

        public MainMenuController(MainMenuViewModel model, LoginRequester loginRequester)
        {
            _model = model;
            _loginRequester = loginRequester;

            _model.LoginButtonPressed.Subscribe(OnLoginButtonPressed)
                .AddTo(_disposables);
        }

        private void OnLoginButtonPressed(Unit _)
        {
            _loginRequester.Login();
        }

        public void Dispose()
        {
            foreach (var disposable in _disposables)
            {
                disposable.Dispose();
            }
        }
    }
}