//******************************************************************************//
// LogDashViewModelLocator.cs
// 12/4/2023
//
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
// RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
// COMPANY.
//
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
//
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
//
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
// PENALTIES.
//
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
// DESTROY BY ANY  METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
// RECONSTRUCTION OF THE DOCUMENT.
// POC: Alex Kravchenko (1118268)
//******************************************************************************//

// Ignore Spelling: Locator

using CommonServiceLocator;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Messaging;
using Raytheon.LogDashboard.Model;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media;

namespace Raytheon.LogDashboard.ViewModel
{
    public class LogDashViewModelLocator : ViewModelBase
    {
        public LogDashViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            SimpleIoc.Default.Register<LogDashboardViewModel>();
            SimpleIoc.Default.Register<ImportLogsProcessViewModel>();
            SimpleIoc.Default.Register<LogImportTemplateViewModel>();
            SimpleIoc.Default.Register<ReleaseNotesViewModel>();
            SimpleIoc.Default.Register<SearchResultViewModel>();
            SimpleIoc.Default.Register<SettingsViewModel>();
            SimpleIoc.Default.Register<SelectTimeIntervalViewModel>();
            SimpleIoc.Default.Register<SidebarTreeViewModel>();
        }
        public static LogDashboardViewModel LogDashboard => ServiceLocator.Current.GetInstance<LogDashboardViewModel>();

        public static ImportLogsProcessViewModel ImportLogsProcess => ServiceLocator.Current.GetInstance<ImportLogsProcessViewModel>();
        public static LogImportTemplateViewModel LogImportTemplate => ServiceLocator.Current.GetInstance<LogImportTemplateViewModel>();
        public static ReleaseNotesViewModel ReleaseNotes => ServiceLocator.Current.GetInstance<ReleaseNotesViewModel>();
        public static SearchResultViewModel SearchResult => ServiceLocator.Current.GetInstance<SearchResultViewModel>();
        public static SettingsViewModel Settings => ServiceLocator.Current.GetInstance<SettingsViewModel>();
        public static SelectTimeIntervalViewModel SelectTimeInterval => ServiceLocator.Current.GetInstance<SelectTimeIntervalViewModel>();
        public static SidebarTreeViewModel SidebarTree => ServiceLocator.Current.GetInstance<SidebarTreeViewModel>();

        public static ColorTheme AccentColorTheme { get; set; } = new ColorTheme { Name = "BaseLight", Color = new SolidColorBrush(Colors.Black) };
        public static ColorTheme InvertAccentColorTheme { get; set; } = new ColorTheme { Name = "BaseDark", Color = new SolidColorBrush(Colors.White) };

        private ColorTheme selectedColorTheme;
        public ColorTheme SelectedColorTheme
        {
            get => selectedColorTheme ?? (selectedColorTheme = new ColorTheme { Color = new SolidColorBrush(Colors.Cyan), Name = "Cyan" });
            set
            {
                if(selectedColorTheme?.Name != value?.Name)
                {
                    Set(() => SelectedColorTheme, ref selectedColorTheme, value);
                    Messenger.Default.Send(value.Name, "ColorChange");
                }
            }
        }

        private string selectedTheme;
        public string SelectedTheme
        {
            get => selectedTheme;
            set
            {
                if(selectedTheme != value)
                {
                    var accentTheme = AccentColorTheme;
                    var invertTheme = InvertAccentColorTheme;
                    SwapReferences(ref accentTheme, ref invertTheme);
                    AccentColorTheme = accentTheme;
                    InvertAccentColorTheme = invertTheme;

                    Set(() => SelectedTheme, ref selectedTheme, value);

                    Messenger.Default.Send(value, "ThemeChange");
                }
            }
        }
        private static void SwapReferences(ref ColorTheme theme1, ref ColorTheme theme2)
        {
            (theme1, theme2) = (theme2, theme1);
        }

        public string ErrorLogger32DefaultLocation => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Raytheon", "ErrorLogger", "ErrorLogger.ini");
        public string ErrorLogger64DefaultLocation => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Raytheon", "ErrorLogger64", "ErrorLogger64.ini");

    }
}
