using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Text;

namespace INT_LKD_2.DataStore
{
    #region UserGroup
    public class UserGroup
    {
        #region Field
        private UserGroupItem m_Level1;
        private UserGroupItem m_Level2;
        private UserGroupItem m_Level3;
        private UserGroupItem m_Admin;
        #endregion

        #region Constructor
        public UserGroup()
        {
            this.Initialize();
        }
        #endregion

        #region Property
        public UserGroupItem Level1
        {
            get { return this.m_Level1; }
            set { this.m_Level1 = value; }
        }
        public UserGroupItem Level2
        {
            get { return this.m_Level2; }
            set { this.m_Level2 = value; }
        }
        public UserGroupItem Level3
        {
            get { return this.m_Level3; }
            set { this.m_Level3 = value; }
        }
     
        public UserGroupItem Admin
        {
            get { return this.m_Admin; }
            set { this.m_Admin = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Level1 = new UserGroupItem();
            this.Level2 = new UserGroupItem();
            this.Level3 = new UserGroupItem();
            this.Admin = new UserGroupItem();
        }

        public bool GetSet1AccessRight(Define.E_FormStore display)
        {
            bool ret = false;

            return ret;
        }
        public bool GetSet2AccessRight(Define.E_FormStore display)
        {
            bool ret = false;

            return ret;
        }
        public bool GetSet3AccessRight(Define.E_FormStore display)
        {
            bool ret = false;

            return ret;
        }
        #endregion
    }
    #endregion
    #region UserGroupItem
    public class UserGroupItem
    {
        #region Field
        private bool m_IsMainDisplayProductChange;
        private bool m_IsMainDisplayClear;
        private bool m_IsMainDisplaySubMenu;

        private bool m_IsMenuRecipe;
        private bool m_IsMenuUserSetting;
        private bool m_IsMenuUserGroupEditor;
        private bool m_IsMenuIOTest;
        private bool m_IsMenuHistoryLog;
        private bool m_IsMenuInspectionLog;
        private bool m_IsMenuAlarmLog;
        private bool m_IsMenuInformation;
        private bool m_IsMenuEquipment;
        private bool m_IsMenuEthernet;
        #endregion

        #region Constructor
        public UserGroupItem()
        {
            this.Initialize();
        }
        #endregion

        #region Property
        public bool IsMainDisplayProductChange
        {
            get { return this.m_IsMainDisplayProductChange; }
            set { this.m_IsMainDisplayProductChange = value; }
        }
        public bool IsMainDisplayClear
        {
            get { return this.m_IsMainDisplayClear; }
            set { this.m_IsMainDisplayClear = value; }
        }
        public bool IsMainDisplaySubMenu
        {
            get { return this.m_IsMainDisplaySubMenu; }
            set { this.m_IsMainDisplaySubMenu = value; }
        }

        public bool IsMenuRecipe
        {
            get { return this.m_IsMenuRecipe; }
            set { this.m_IsMenuRecipe = value; }
        }
        public bool IsMenuUserSetting
        {
            get { return this.m_IsMenuUserSetting; }
            set { this.m_IsMenuUserSetting = value; }
        }
        public bool IsMenuUserGroupEditor
        {
            get { return this.m_IsMenuUserGroupEditor; }
            set { this.m_IsMenuUserGroupEditor = value; }
        }
        public bool IsMenuIOTest
        {
            get { return this.m_IsMenuIOTest; }
            set { this.m_IsMenuIOTest = value; }
        }

        public bool IsMenuHistoryLog
        {
            get { return this.m_IsMenuHistoryLog; }
            set { this.m_IsMenuHistoryLog = value; }
        }
        public bool IsMenuInspectionLog
        {
            get { return this.m_IsMenuInspectionLog; }
            set { this.m_IsMenuInspectionLog = value; }
        }
        public bool IsMenuAlarmLog
        {
            get { return this.m_IsMenuAlarmLog; }
            set { this.m_IsMenuAlarmLog = value; }
        }
        public bool IsMenuInformation
        {
            get { return this.m_IsMenuInformation; }
            set { this.m_IsMenuInformation = value; }
        }
        public bool IsMenuEquipment
        {
            get { return this.m_IsMenuEquipment; }
            set { this.m_IsMenuEquipment = value; }
        }
        public bool IsMenuEthernet
        {
            get { return this.m_IsMenuEthernet; }
            set { this.m_IsMenuEthernet = value; }
        }

        public bool IsMainEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMainDisplayProductChange == true || this.IsMainDisplayClear == true
                    || this.IsMainDisplaySubMenu == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsRecipeEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuRecipe == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsUserEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuUserSetting == true || this.IsMenuUserGroupEditor == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsManualEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuIOTest == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsLogEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuHistoryLog == true || this.IsMenuInspectionLog == true || this.IsMenuAlarmLog == true)
                    ret = true;

                return ret;
            }
        }
        public bool IsSystemEnable
        {
            get
            {
                bool ret = false;

                if (this.IsMenuInformation == true || this.IsMenuEquipment == true || this.IsMenuEthernet == true)
                    ret = true;

                return ret;
            }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsMainDisplayProductChange = false;
            this.IsMainDisplayClear = false;
            this.IsMainDisplaySubMenu = false;

            this.IsMenuRecipe = false;
            this.IsMenuUserSetting = false;
            this.IsMenuUserGroupEditor = false;
            this.IsMenuIOTest = false;
            this.IsMenuHistoryLog = false;
            this.IsMenuInspectionLog = false;
            this.IsMenuAlarmLog = false;
            this.IsMenuInformation = false;
            this.IsMenuEquipment = false;
            this.IsMenuEthernet = false;
        }
        #endregion
    }
    #endregion
    #region StructUserGroupItem(총 메뉴 개수 30개)
    [StructLayout(LayoutKind.Sequential)]
    public struct StructUserGroupItem
    {
        public bool IsMainDisplayRecipeChange;
        public bool IsMainDisplayClear;
        public bool IsMainDispalySubMenu;

        public bool IsMenuRecipe;
        public bool IsMenuUserSetting;
        public bool IsMenuUserGroupEditor;
        public bool IsMenuIOTest;
        public bool IsMenuEquipmentLog;
        public bool IsMenuCheckLog;
        public bool IsMenuAlarmList;
        public bool IsMenuInformation;
        public bool IsMenuStatus;
        public bool IsMenuEthernet;

        public bool Dummy1;
        public bool Dummy2;
        public bool Dummy3;
        public bool Dummy4;
        public bool Dummy5;
        public bool Dummy6;
        public bool Dummy7;
        public bool Dummy8;
        public bool Dummy9;
        public bool Dummy10;
        public bool Dummy11;
        public bool Dummy12;
        public bool Dummy13;
        public bool Dummy14;
        public bool Dummy15;
        public bool Dummy16;
        public bool Dummy17;
    }
    #endregion

    #region UserItem
    public class UserItem
    {
        #region Field
        private bool m_IsUpdate;

        private string m_ID;
        private string m_Password;
        private string m_ResetPW;

        private int m_ExpireId;
        private int m_ExpirePassword;

        private bool m_IsLockAccount;
        private bool m_IsLockPassword;

        private DateTime m_DatePasswordRegister;
        private DateTime m_DateIdLogin;
        private DateTime m_DatePasswordExpire;
        private DateTime m_DateIdExpire;

        private Define.E_UserGroup m_Group;

        private bool m_IsAdmin;

        private int m_ActiveLevel;

        private int m_IsFirstPassword;
        private int m_LoginFailCount;
        #endregion

        #region Constructor
        public UserItem()
        {
            this.Initialize();
        }
        #endregion

        #region Property
        public bool IsUpdate
        {
            get { return this.m_IsUpdate; }
            set { this.m_IsUpdate = value; }
        }

        public string ID
        {
            get { return this.m_ID; }
            set { this.m_ID = value; }
        }
        public string Password
        {
            get { return this.m_Password; }
            set { this.m_Password = value; }
        }
        public string ResetPW
        {
            get { return this.m_ResetPW; }
            private set { this.m_ResetPW = value; }
        }

        public int ExpireId
        {
            get { return this.m_ExpireId; }
            set { this.m_ExpireId = value; }
        }
        public int ExpirePassword
        {
            get { return this.m_ExpirePassword; }
            set { this.m_ExpirePassword = value; }
        }

        public bool IsLockAccount
        {
            get { return this.m_IsLockAccount; }
            set { this.m_IsLockAccount = value; }
        }
        public bool IsLockPassword
        {
            get { return this.m_IsLockPassword; }
            set { this.m_IsLockPassword = value; }
        }

        public DateTime DatePasswordRegister
        {
            get { return this.m_DatePasswordRegister; }
            set { this.m_DatePasswordRegister = value; }
        }
        public DateTime DateIdLogin
        {
            get { return this.m_DateIdLogin; }
            set { this.m_DateIdLogin = value; }
        }
        public DateTime DatePasswordExpire
        {
            get { return this.m_DatePasswordExpire; }
            set { this.m_DatePasswordExpire = value; }
        }
        public DateTime DateIdExpire
        {
            get { return this.m_DateIdExpire; }
            set { this.m_DateIdExpire = value; }
        }

        public Define.E_UserGroup Group
        {
            get { return this.m_Group; }
            set { this.m_Group = value; }
        }

        public bool IsAdmin
        {
            get { return this.m_IsAdmin; }
            set { this.m_IsAdmin = value; }
        }

        public int ActiveLevel
        {
            get { return this.m_ActiveLevel; }
            set { this.m_ActiveLevel = value; }
        }

        public int IsFirstPassword
        {
            get { return this.m_IsFirstPassword; }
            set { this.m_IsFirstPassword = value; }
        }
        public int LoginFailCount
        {
            get { return this.m_LoginFailCount; }
            set { this.m_LoginFailCount = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.IsUpdate = false;

            this.ID = "";
            this.Password = "Password12!";
            this.ResetPW = "Password12!";

            this.ExpireId = 0;
            this.ExpirePassword = 0;

            this.DatePasswordRegister = DateTime.Now;
            this.DateIdLogin = DateTime.Now;
            this.DatePasswordExpire = DateTime.Now;
            this.DateIdExpire = DateTime.Now;

            this.Group = Define.E_UserGroup.None;

            this.IsAdmin = false;

            this.ActiveLevel = 1;

            this.IsFirstPassword = 1;   //[1] 최초 비밀번호(비밀번호 변경창 띄우기), [0] 비밀번호 변경완료됨
            this.LoginFailCount = 5;
        }

        public int GetPasswordExpiryDday()
        {
            int ret = 0;
            DateTime timeNow = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            TimeSpan dayDiff;

            if (this.Group == Define.E_UserGroup.Admin || this.Group == Define.E_UserGroup.Developer)
                ret = 9999;
            else
            {
                dayDiff = timeNow.Date - this.DatePasswordExpire.Date;
                ret = dayDiff.Days;
            }

            return ret;
        }

        public bool CheckID(string id)
        {
            bool ret = false;


            return ret;
        }
        public bool CheckPassword(string pass)
        {
            bool ret = false;

            return ret;
        }
        #endregion
    }
    #endregion
}
