using System;
using System.ComponentModel.Composition;
using System.ServiceModel.DomainServices.Client;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using TaskIt.Assets.Resources;
using TaskIt.Core;
using TaskIt.Infrastructure;
using TaskIt.Web;

namespace TaskIt.ViewModels
{
    [Export]
    public class HomeViewModel : TaskItViewModelBase
    {
        public HomeViewModel()
        {
            DataProvider.GetUsers(OnUsersLoaded);
        }

        static void OnUsersLoaded(LoadOperation<TaskItUser> lo)
        {
            if (!lo.HasError)
            {
                return;
            }
            Utils.ShowErrorMessage(ErrorStrings.Message_LoadingUsersFailed, lo.Error.Message);
            lo.MarkErrorAsHandled();
            // TODO: Ross - Shut down the app if users cannot be loaded
        }

        public virtual void OnNavigate(ModuleEnum module)
        {            
            Messenger.Default.Send(module);
        }

        # region Commands

        private RelayCommand<ModuleEnum> _navigateCommand;
        public RelayCommand<ModuleEnum> NavigateCommand
        {
            get { return _navigateCommand ?? (_navigateCommand = new RelayCommand<ModuleEnum>(OnNavigate)); }
        }

        # endregion

        # region ModuleEnums

        public ModuleEnum ModuleTasks
        {
            get { return ModuleEnum.Tasks; }
        }

        public ModuleEnum ModuleSettings
        {
            get { return ModuleEnum.Settings; }
        }

        public ModuleEnum ModuleDashboard
        {
            get { return ModuleEnum.Dashboard; }
        }

        public ModuleEnum ModuleHelp
        {
            get { return ModuleEnum.Help; }
        }

        # endregion

        # region Icons

        public Uri IconTasksUri
        {
            get { return GetLargeIconUri("Tasks"); }
        }

        public Uri IconDashboardUri
        {
            get { return GetLargeIconUri("Dashboard"); }
        }

        public Uri IconSettingsUri
        {
            get { return GetLargeIconUri("Settings"); }
        }

        public Uri IconHelpUri
        {
            get { return GetLargeIconUri("Help"); }
        }

        # endregion 

        # region Resource Strings

        public string ResourcePageLinkTasks
        {
            get { return ApplicationStrings.PageLink_Tasks; }
        }

        public string ResourcePageLinkSettings
        {
            get { return ApplicationStrings.PageLink_Settings; }
        }

        public string ResourcePageLinkDashboard
        {
            get { return ApplicationStrings.PageLink_Dashboard; }
        }

        public string ResourcePageLinkHelp
        {
            get { return ApplicationStrings.PageLink_Help; }
        }

        # endregion

    }
}
