using Microsoft.Extensions.DependencyInjection;
using System;

namespace BBWYB.Client.ViewModels
{
    public class ViewModelLocator
    {
        private IServiceProvider sp;

        public ViewModelLocator()
        {
            sp = (App.Current as App).ServiceProvider;
        }

        public bool IsCreateWareManager { get; private set; }

        public bool IsCreateWareStock { get; private set; }

        public bool IsCreateOrderList { get; private set; }


        public MainViewModel Main
        {
            get
            {
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<MainViewModel>();
                }
            }
        }

        public WareManagerViewModel WareManager
        {
            get
            {
                IsCreateWareManager = true;
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<WareManagerViewModel>();
                }
            }
        }

        public BindingPurchaseProductViewModel BindingPurchaseProduct
        {
            get
            {
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<BindingPurchaseProductViewModel>();
                }
            }
        }

        public OrderViewModel OrderVM
        {
            get
            {
                IsCreateOrderList = true;
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<OrderViewModel>();
                }
            }
        }

        public ShopSettingViewModel ShopSetting
        {
            get
            {
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<ShopSettingViewModel>();
                }
            }
        }

        public ChoosePurchaseSchemeViewModel ChoosePurchaseScheme
        {
            get
            {
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<ChoosePurchaseSchemeViewModel>();
                }
            }
        }

        public OnlinePurchaseViewModel OnlinePurchase
        {
            get
            {
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<OnlinePurchaseViewModel>();
                }
            }
        }

        public EditPriceViewModel EditPrice
        {
            get
            {
                using (var s = sp.CreateScope())
                {
                    return s.ServiceProvider.GetRequiredService<EditPriceViewModel>();
                }
            }
        }

        public UpdatePurchaseTaskViewModel UpdatePurchaseTask
        {
            get
            {
                using var s = sp.CreateScope();
                return s.ServiceProvider.GetRequiredService<UpdatePurchaseTaskViewModel>();
            }
        }

        public WebVM WebVM
        {
            get
            {
                using var s = sp.CreateScope();
                return s.ServiceProvider.GetRequiredService<WebVM>();
            }
        }
    }
}