using Foresight.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IronIntel.Contractor.Users
{
    public static class Acl
    {
        public static string[] GetUserAvailableContractors(string useriid)
        {
            const string SQL = @"select distinct CONTRACTORID from USERTOCONTRACTOR where USERIID={0}
                                or USERIID in(select GROUPID from USERGROUPMAP where USERIID ={0})";
            FIDbAccess db = SystemParams.GetDbInstance();
            DataTable dt = db.GetDataTableBySQL(SQL, useriid);
            List<string> list = new List<string>();
            foreach (DataRow dr in dt.Rows)
            {
                list.Add(FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty));
            }
            return list.ToArray();
        }

        public static AppModuleInfo[] GetAvailableAppModuleInfos(UserInfo user)
        {
            return AppModulesManagement.GetAvailableAppModuleInfos(user);
        }

        public static AppModuleInfo[] GetAvailableAppModuleInfos(string useriid)
        {
            UserInfo ui = UserManagement.GetUserByIID(useriid);
            return GetAvailableAppModuleInfos(ui);
        }

       public static SecurityNavigateItem[] GetSecurityNavigateItems(UserInfo user)
        {
            return AppModulesManagement.GetSecurityNavigateItems(user);
        }

        
    }
}
