using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.Hosting;
using Microsoft.AspNetCore.Identity;
using ElectroShop.Models;
using ElectroShop.Services;

namespace ElectroShop.ViewModels
{
    public class DefaultViewModel : MasterPageViewModel
    {
        private readonly UserService userService;

        public DefaultViewModel(UserService userService)
        {
            this.userService = userService;
        }

        public override async Task PreRender()
        {
            if (UserNameGlobal != null)
            {
                var role = userService.GetRoleByUsername(UserNameGlobal);
                switch (role)
                {
                    case "Administrator":
                        Context.RedirectToRoute("UserManagement");
                        break;
                    case "Warehouseman":
                        Context.RedirectToRoute("ElectronicComponentManagement");
                        break;
                    case "Designer":
                        Context.RedirectToRoute("ElectronicComponentManagement");
                        break;
                    default:
                        break;
                }
            }


            await base.PreRender();
        }
    }
}
