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

namespace INT63DC_2C.Part11_UserManager
{
    #region UserItem
    public class UserItem
    {
        #region Field
        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_DateIdExpire;
        private DateTime m_DatePasswordExpire;

        private DataStore.UserGroup m_Group;

        private bool m_IsAdmin;

        private int m_ActiveLevel;

        private int m_IsFirstPassword;
        #endregion

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

        #region Property
        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 DateIdExpire
        {
            get { return this.m_DateIdExpire; }
            set { this.m_DateIdExpire = value; }
        }
        public DateTime DatePasswordExpire
        {
            get { return this.m_DatePasswordExpire; }
            set { this.m_DatePasswordExpire = value; }
        }

        public DataStore.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; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.ID = "-";
            this.Password = "-";
            this.ResetPW = "Password12!";

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

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

            this.Group = DataStore.UserGroup.None;

            this.IsAdmin = false;

            this.ActiveLevel = 1;

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

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

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

            return ret;
        }
        #endregion
    }
    #endregion

    #region UserGroup
    public class UserGroup
    {
        #region Field
        private UserGroupItem m_Level1;
        private UserGroupItem m_Level2;
        private UserGroupItem m_Level3;
        private UserGroupItem m_NotLogin;
        #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 NotLogin
        {
            get { return this.m_NotLogin; }
            set { this.m_NotLogin = value; }
        }
        #endregion

        #region Method
        private void Initialize()
        {
            this.Level1 = new UserGroupItem();
            this.Level2 = new UserGroupItem();
            this.Level3 = new UserGroupItem();
            this.NotLogin = new UserGroupItem();
        }
        #endregion
    }
    #endregion
    #region UserGroupItem
    public class UserGroupItem
    {
        #region Field
        private bool m_IsMainDisplayProductNo;
        private bool m_IsMainDisplayWeightSetting;
        private bool m_IsMainDisplayClear;
        private bool m_IsMainDisplaySubMenu;

        private bool m_IsMenuInformation;
        private bool m_IsMenuConfiguration;
        private bool m_IsMenuCommunication;
        private bool m_IsMenuCalibration;
        private bool m_IsMenuSystem;
        private bool m_IsMenuMotor;
        private bool m_IsMenuIOTest;
        private bool m_IsMenuEquipment;
        private bool m_IsMenuUpdate;
        private bool m_IsMenuInitialization;
        private bool m_IsMenuTime;
        private bool m_IsMenuDataBackup;
        private bool m_IsMenuStatistics;
        private bool m_IsMenuViewer;
        private bool m_IsMenuUser;
        private bool m_IsMenuUserGroupEditor;
        #endregion

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

        #region Property
        public bool IsMainDisplayProductNo
        {
            get { return this.m_IsMainDisplayProductNo; }
            set { this.m_IsMainDisplayProductNo = value; }
        }
        public bool IsMainDisplayWeightSetting
        {
            get { return this.m_IsMainDisplayWeightSetting; }
            set { this.m_IsMainDisplayWeightSetting = 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 IsMenuTime
        {
            get { return this.m_IsMenuTime; }
            set { this.m_IsMenuTime = value; }
        }
        public bool IsMenuInformation
        {
            get { return this.m_IsMenuInformation; }
            set { this.m_IsMenuInformation = value; }
        }
        public bool IsMenuDataBackup
        {
            get { return this.m_IsMenuDataBackup; }
            set { this.m_IsMenuDataBackup = value; }
        }
        public bool IsMenuCalibration
        {
            get { return this.m_IsMenuCalibration; }
            set { this.m_IsMenuCalibration = value; }
        }
        public bool IsMenuCommunication
        {
            get { return this.m_IsMenuCommunication; }
            set { this.m_IsMenuCommunication = value; }
        }
        public bool IsMenuConfiguration
        {
            get { return this.m_IsMenuConfiguration; }
            set { this.m_IsMenuConfiguration = value; }
        }
        public bool IsMenuSystem
        {
            get { return this.m_IsMenuSystem; }
            set { this.m_IsMenuSystem = value; }
        }
        public bool IsMenuMotor
        {
            get { return this.m_IsMenuMotor; }
            set { this.m_IsMenuMotor = value; }
        }
        public bool IsMenuUpdate
        {
            get { return this.m_IsMenuUpdate; }
            set { this.m_IsMenuUpdate = value; }
        }
        public bool IsMenuInitialization
        {
            get { return this.m_IsMenuInitialization; }
            set { this.m_IsMenuInitialization = value; }
        }
        public bool IsMenuEquipment
        {
            get { return this.m_IsMenuEquipment; }
            set { this.m_IsMenuEquipment = value; }
        }
        public bool IsMenuIOTest
        {
            get { return this.m_IsMenuIOTest; }
            set { this.m_IsMenuIOTest = value; }
        }
        public bool IsMenuStatistics
        {
            get { return this.m_IsMenuStatistics; }
            set { this.m_IsMenuStatistics = value; }
        }
        public bool IsMenuUser
        {
            get { return this.m_IsMenuUser; }
            set { this.m_IsMenuUser = value; }
        }
        public bool IsMenuViewer
        {
            get { return this.m_IsMenuViewer; }
            set { this.m_IsMenuViewer = value; }
        }
        public bool IsMenuUserGroupEditor
        {
            get { return this.m_IsMenuUserGroupEditor; }
            set { this.m_IsMenuUserGroupEditor = value; }
        }
        #endregion

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

            this.IsMenuTime = false;
            this.IsMenuInformation = true;
            this.IsMenuDataBackup = false;
            this.IsMenuCalibration = false;
            this.IsMenuCommunication = false;
            this.IsMenuConfiguration = false;
            this.IsMenuSystem = false;
            this.IsMenuMotor = false;
            this.IsMenuUpdate = false;
            this.IsMenuInitialization = false;
            this.IsMenuEquipment = false;
            this.IsMenuIOTest = false;
            this.IsMenuStatistics = false;
            this.IsMenuUser = true;
            this.IsMenuUserGroupEditor = false;
            this.IsMenuViewer = false;
        }
        #endregion
    }
    #endregion
    #region StructUserGroupItem
    [StructLayout(LayoutKind.Sequential)]
    public struct StructUserGroupItem
    {
        public bool IsMainDisplayProductNo;
        public bool IsMainDisplayWeightSetting;
        public bool IsMainDisplayClear;
        public bool IsMainDispalySubMenu;

        public bool IsMenuTimeSetting;
        public bool IsMenuInformation;
        public bool IsMenuDataBackup;
        public bool IsMenuCalibration;
        public bool IsMenuCommunication;
        public bool IsMenuConfiguration;
        public bool IsMenuSystemSetting;
        public bool IsMenuMotorSetting;
        public bool IsMenuUpdate;
        public bool IsMenuFactoryReset;
        public bool IsMenuEquipmentSetting;
        public bool IsMenuIOTest;
        public bool IsMenuDataStatistics;
        public bool IsMenuUserSetting;
        public bool IsMenuUserGroupSetting;
        public bool IsMenuDataViewer;

        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;
        public bool Dummy18;
        public bool Dummy19;
        public bool Dummy20;
    }
    #endregion
}
