using System;
using System.Collections.Generic;
using Code.Domain;
using Code.InterfaceAdapters.MainMenu;
using Code.InterfaceAdapters.Profile;
using Code.View;
using UnityEngine;

namespace Code.Main
{
    public class Installer : MonoBehaviour
    {
        [SerializeField] private MainMenuView _mainMenuView;
        [SerializeField] private ProfileView _profileView;
        
        private List<IDisposable> _disposables;
        
        private void Awake()
        {
            var mainMenuViewModel = new MainMenuViewModel();
            _mainMenuView.Configure(mainMenuViewModel);

            var profileViewModel = new ProfileViewModel();
            _profileView.Configure(profileViewModel);


            var loginUseCase = new LoginUseCase();
            var mainMenuPresenter = new MainMenuPresenter(mainMenuViewModel);
            _disposables.Add(mainMenuPresenter);
            var mainMenuController = new MainMenuController(mainMenuViewModel, loginUseCase);
            _disposables.Add(mainMenuController);

            new ProfilePresenter(profileViewModel);
        }

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