using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using BankTVUpdater.Consts;
using BankTVUpdater.Helpers;

namespace BankTVUpdater
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            if (this.checkArgsIsSilentMode(e.Args))
            {
                UpdateHelper.UpdateApp();
                Shutdown();
            }   //if
            else if (this.checkArgsIsSilentModeNoMovies(e.Args))
            {
                UpdateHelper.UpdateAppNoMovies();
                Shutdown();
            }   //if
            else if (this.checkArgsIsCleanMode(e.Args))
            {
                ProcessHelper.CleanApp();
                Shutdown();
            }   //if
        }

        private bool checkArgsIsSilentMode(string[] args)
        {
            if (args == null)
            {
                return false;
            }   //if
            if (args.Count() == 0)
            {
                return false;
            }   //if
            foreach (string arg in args)
            {
                if (StringHelper.RemoveSpecialCharacters(arg).Equals(GlobalConsts.SILENT_MODE_ARG))
                {
                    return true;
                }   //if
            }   //for
            return false;
        }

        private bool checkArgsIsSilentModeNoMovies(string[] args)
        {
            if (args == null)
            {
                return false;
            }   //if
            if (args.Count() == 0)
            {
                return false;
            }   //if
            foreach (string arg in args)
            {
                if (StringHelper.RemoveSpecialCharacters(arg).Equals(GlobalConsts.SILENT_NO_MOVIE_MODE_ARG))
                {
                    return true;
                }   //if
            }   //for
            return false;
        }

        private bool checkArgsIsCleanMode(string[] args)
        {
            if (args == null)
            {
                return false;
            }   //if
            if (args.Count() == 0)
            {
                return false;
            }   //if
            foreach (string arg in args)
            {
                if (StringHelper.RemoveSpecialCharacters(arg).Equals(GlobalConsts.CLEAN_MODE_ARG))
                {
                    return true;
                }   //if
            }   //for
            return false;
        }


    }
}
