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

namespace WebAPIBase.NetCore.BusinessCore
{
    public class Info
    {
        private static GetCurrentUser gcu;

        private static Hashtable currentList = new Hashtable();

        public static GetCurrentUser GCU
        {
            set
            {
                gcu = value;
            }
        }

        public static CurrentInfo Current
        {
            get
            {
                int currentUserCode = gcu.GetCurrentUserCode();
                if (currentList.ContainsKey(currentUserCode))
                {
                    return (CurrentInfo)currentList[currentUserCode];
                }
                CurrentInfo currentInfo = CurrentInfo.Instance(currentUserCode);
                try
                {
                    currentList.Add(currentUserCode, currentInfo);
                }
                catch
                {
                }
                return currentInfo;
            }
        }

        public static void Clear()
        {
            currentList.Clear();
        }
    }


    public abstract class GetCurrentUser
    {
        public abstract int GetCurrentUserCode();
    }

    public class CurrentInfo
    {
        public int UserCode;

        public string UserName;

        public FdcUser fdcUser;

        private CurrentInfo()
        {
        }

        private CurrentInfo(int usercode)
        {
            init(usercode);
        }

        private void init(int usercode)
        {
            fdcUser = FdcUnitStructure.Instance.GetFdcUserByCode(usercode);
            if (fdcUser != null)
            {
                int.TryParse(fdcUser.UserCode, out UserCode);
                UserName = fdcUser.UserName;
            }
            else
            {
                UserCode = 0;
                UserName = "-";
            }
        }

        public static CurrentInfo Instance(int usercode)
        {
            return new CurrentInfo(usercode);
        }
    }

    public enum RightScope
    {
        无,
        个人,
        部门
    }

    public class FdcFunctionUnit
    {
        public string FunctionCode;

        public FdcUnit unit;

        public int IsPerson;
    }
}
