using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static MMoneyCoderSharp.DBDefine;

namespace MMoneyCoderSharp.Data.Request
{
    internal abstract class ACandleData : ADataObject
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="recvStockName"></param>
        /// <param name="recvDataLength"></param>
        public ACandleData(봉차트세부종목 recvDataType, 데이터기간 recvDataLength)
        {
            this.mDataLength = recvDataLength;
            this.mDataType = recvDataType;
            this.setQuery();
        }

        protected 데이터기간 mDataLength;

        protected 봉차트세부종목 mDataType;

        protected string mStockCode = string.Empty;

        protected string queryForecastToday = @"";

        protected string queryForecastLast = @"";

        protected string queryIndexNow = @"";

        protected string queryIndexToday = @"";

        protected string queryIndexLast = @"";

        protected string queryQuantityToday = @"";

        protected string queryQuantityLast = @"";

        
        public override IDataRequest buildData()
        {
           
                switch (mDataType)
                {
                    case 봉차트세부종목.예상지수:
                        buildQueryMethod(queryForecastToday, queryForecastLast);
                        break;
                    case 봉차트세부종목.일반지수:
                        buildQueryMethod(queryIndexNow, queryIndexLast, queryIndexToday);
                        break;
                    case 봉차트세부종목.거래량:
                        buildQueryMethod(queryIndexNow, queryQuantityLast, queryQuantityToday);
                        break;
                }
          
         
            return this;

        }

        private void buildQueryMethod(string query1, string query2, string query3 = null)
        {

            if (this.mStockCode != string.Empty)
            {
                mRequestQuery.Add("현재", string.Format(query1, this.mStockCode));

                if (mDataLength == 데이터기간.일 && query3 != null)
                {
                    mRequestQuery.Add("누적", string.Format(query3, this.mStockCode));
                }
                else
                {
                    mRequestQuery.Add("누적", String.Format(query2, this.mDataLength.GetStringValue(), this.mStockCode));
                }

            }
            else
            {

                mRequestQuery.Add("현재", query1);

                if (mDataLength == 데이터기간.일 && query3 != null)
                {
                    mRequestQuery.Add("누적", query3);
                }
                else
                {
                    mRequestQuery.Add("누적", String.Format(query2, this.mDataLength.GetStringValue()));
                }
            }
            
        }


        protected abstract void setQuery();

    }

}
