using System;
using System.Collections.Generic;
using FSI.Lib.Helpers;

namespace FSI.BT.Tools
{
    internal class Admin
    {
        public static bool CheckSuperAdminRight()
        {
            if (Global.Settings.SuperAdmin == null)
            {
                return false;
            }

            System.Security.Principal.WindowsIdentity windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();

            if (string.Equals(Global.Settings.SuperAdmin, windowsIdentity.ShortName(), StringComparison.OrdinalIgnoreCase))
                return true;

            return false;
        }

        public static bool CheckAdminRight()
        {
            if (Global.Settings.Admins == null)
            {
                return false;
            }

            List<string> admins = new List<string>(Global.Settings.Admins);

            System.Security.Principal.WindowsIdentity windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();

            foreach (string admin in admins)
            {
                if (string.Equals(admin, windowsIdentity.ShortName(), StringComparison.OrdinalIgnoreCase))
                    return true;
            }

            return false;
        }

        public static bool CheckUserRight()
        {
            if (Global.Settings.Users == null)
            {
                return false;
            }

            List<string> users = new List<string>(Global.Settings.Users);

            System.Security.Principal.WindowsIdentity windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();

            foreach (string user in users)
            {
                if (string.Equals(user, windowsIdentity.ShortName(), StringComparison.OrdinalIgnoreCase))
                    return true;
            }

            return false;
        }
    }
}
