using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.IO;
using System.Security.Cryptography;
using System.Data;
using System.Text.RegularExpressions;
using System.Net.Sockets;
using System.Globalization;
using System.Threading;
using System.Diagnostics;
using System.Net;

using SystemX.Net.BaseProtocol;
using System.Xml.Linq;
using static SystemX.Net.Platform.Common.Util.LogMessage;
using System.Data.SqlClient;

namespace SystemX.Net.Middleware.Log.DeleteProc
{
    public class DeleteProcSystem
    {
        public Stopwatch stDeleteLogScanTimer;

        public DeleteProcSystem()
        {
            stDeleteLogScanTimer = new Stopwatch();
        }

        protected void ScanTimerStart()
        {
            stDeleteLogScanTimer.Start();
        }

        protected void ScanTimerRestart()
        {
            stDeleteLogScanTimer.Restart();
        }

        protected long GetTimerTime()
        {
            return stDeleteLogScanTimer.ElapsedMilliseconds;
        }

        protected bool GetTimeOverState(long lLimitTime)
        {
            return (stDeleteLogScanTimer.ElapsedMilliseconds >= lLimitTime) ? true : false;
        }
    }

    public class DeleteProcOption
    {
        public enum eLogCheckItem
        {
            Summary = 0,
            ShortTerm = 1,
            LongTerm = 2
        }

        //Option
        public eLogCheckItem ProcChkItem;

        public long lLogScanTimeVal;

        public int nSummaryScanItemCnt;
        public int nShortLogScanItemCnt;
        public int nLongLogScanItemCnt;

        public int nSummaryDeleteNum;

        public DeleteProcOption()
        {
            ProcChkItem = eLogCheckItem.Summary;

            //3 Minute
            //Test 10000
            lLogScanTimeVal = 10000; //180000;

            nSummaryScanItemCnt = 100;
            nShortLogScanItemCnt = 100;
            nLongLogScanItemCnt = 100;

            nSummaryDeleteNum = 5;
        }
    }

    public class DeleteProcInfo : DeleteProcSystem
    {
        public int[] nHistSummaryDeleteList;
        public int nHistSummaryDeleteSize;
        public int nHistSummaryDeletePos;
        //
        public int[] nShortLogSummaryDeleteListNo;
        public int[] nShortLogSummaryDeleteListAccessSt;
        public int[] nShortLogSummaryDeleteListAccessEn;

        public int nShortLogSummaryDeleteSize;
        public int nShortLogSummaryDeletePos;

        public bool bShortLogDataCheckResult;
        public int nShortLogDeleteProcPos;
        public bool bShortLogDataDeleteResult;
        //
        public int[] nLongLogSummaryDeleteListNo;
        public int[] nLongLogSummaryDeleteListAccessSt;
        public int[] nLongLogSummaryDeleteListAccessEn;

        public int nLongLogSummaryDeleteSize;
        public int nLongLogSummaryDeletePos;

        public bool bLongLogDataCheckResult;
        public int nLongLogDeleteProcPos;
        public bool bLongLogDataDeleteResult;
        //
        //Option
        public DeleteProcOption DeleteProcOp;

        public DeleteProcInfo()
        {
            ScanTimerStart();

            InitMember();
        }

        private void InitMember()
        {
            nHistSummaryDeleteList = new int[1];
            nHistSummaryDeleteSize = 0;
            nHistSummaryDeletePos = 0;

            nShortLogSummaryDeleteListNo = new int[1];
            nShortLogSummaryDeleteListAccessSt = new int[1];
            nShortLogSummaryDeleteListAccessEn = new int[1];

            nShortLogSummaryDeleteSize = 0;
            nShortLogSummaryDeletePos = 0;

            bShortLogDataCheckResult = false;
            nShortLogDeleteProcPos = 0;
            bShortLogDataDeleteResult = false;

            nLongLogSummaryDeleteListNo = new int[1];
            nLongLogSummaryDeleteListAccessSt = new int[1];
            nLongLogSummaryDeleteListAccessEn = new int[1];

            nLongLogSummaryDeleteSize = 0;
            nLongLogSummaryDeletePos = 0;

            bLongLogDataCheckResult = false;
            nLongLogDeleteProcPos = 0;
            bLongLogDataDeleteResult = false;

            DeleteProcOp = new DeleteProcOption();
        }

        public bool GetScanTimeState()
        {
            return GetTimeOverState(DeleteProcOp.lLogScanTimeVal);
        }

        public void ResetScanTimeState()
        {
            ScanTimerRestart();
        }
    }
}
