using System;
using System.Collections.Generic;
using System.Linq;
using BO.AppServer.Metadata.Enums;

namespace BO.AppServer.Business.Security
{
    internal class RoleUtils
    {
        public static IEnumerable<string> GetElevatedRoles(bool isNormalized = false)
        {
            return GetRoles(isNormalized, RoleEnum.System, RoleEnum.Console, RoleEnum.Service);
        }

        public static IEnumerable<string> GetUserRoles(bool isNormalized = false)
        {
            return GetRoles(isNormalized, RoleEnum.User, RoleEnum.Uploader, RoleEnum.Downloader, RoleEnum.Accountant, RoleEnum.Admin);
        }

        public static IEnumerable<string> GetAdminRoles(bool isNormalized = false)
        {
            return GetRoles(isNormalized, RoleEnum.SuperAdmin,RoleEnum.System);
        }

        public static IEnumerable<string> GetSystemRoles(bool isNormalized = false)
        {
            return GetRoles(isNormalized, RoleEnum.System, RoleEnum.Console, RoleEnum.B2B, RoleEnum.Service);
        }

        public static IEnumerable<string> GetAllRoles(bool isNormalized = false)
        {
            var roles = Enum.GetNames(typeof(RoleEnum));
            return isNormalized ? roles.Select(x => x.ToUpper()) : roles;
        }

        private static IEnumerable<string> GetRoles(bool isNormalized, params RoleEnum[] roles)
        {
            if (roles == null)
                throw new ArgumentNullException(nameof(roles));
            if (roles.Length == 0)
                return Array.Empty<string>();

            return isNormalized ? roles.Select(x => x.ToString().ToUpper()) : roles.Select(x => x.ToString());
        }
    }
}
