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

namespace MMoneyCoderSharp.Data.Request.봉차트
{
    internal class CandleIndustryKOSPI : ACandleData
    {
        public CandleIndustryKOSPI(DBDefine.봉차트세부종목 recvDataType, DBDefine.데이터기간 recvDataLength, string recvStockCode) : base(recvDataType, recvDataLength)
        {

            if (recvDataType == DBDefine.봉차트세부종목.예상지수)
            {
                throw new Exception("업종지수는 예상지수 쿼리가 없음.");
            }


            this.mStockCode = recvStockCode;

        }
        
        protected override void setQuery()
        {
              
            #region 예상지수

        this.queryForecastToday = @"";

            this.queryForecastLast = @"";

            #endregion
            
            #region 지수
        
        this.queryIndexNow = @"SELECT 
                b.f_part_name part_name, 
                a.f_part_vol part_vol, 
                round(f_part_idx / 100, 2) part_idx, 
                f_chg_type chg_type, 
                round(f_part_chg / 100, 2) part_chg, 
                round((f_part_chg / decode(f_chg_type, '+', f_part_idx - f_part_chg, '-', f_part_idx + f_part_chg, 1)) * 100, 2) rate 
            FROM t_index a, t_part b 
            WHERE a.f_part_code = b.f_part_code 
                AND b.f_part_name = '{0}'";

            this.queryIndexToday = @"select 
                a.F_DATA_DAY, 
                a.F_DATA_TIME, 
                a.F_PART_CODE, 
                b.f_part_name, 
                a.F_CHG_TYPE, 
                a.F_PART_CHG / 100 part_chg, 
                a.F_PART_HIGH_IDX / 100 part_high_idx, 
                a.F_PART_LOW_IDX / 100 part_low_idx, 
                a.F_PART_INIT_IDX / 100 part_init_idx, 
                a.F_PART_IDX / 100 part_idx, 
                F_PART_VOL 
            from t_index_his_5M a, t_part b 
            where a.f_part_code = b.f_part_code 
                and b.f_part_name = '{0}'
                and a.f_data_day = (select max(open_day) from v_open_day) 
            order by a.F_DATA_DAY, a.F_DATA_TIME";
        
            this.queryIndexLast = @"select 
                F_DATA_DAY, 
                F_PART_CODE, 
                f_part_name part_name, 
                F_CHG_TYPE chg_type, 
                f_part_vol part_vol, 
                F_PART_CHG / 100 part_chg, 
                F_PART_HIGH_IDX / 100 part_high_idx, 
                F_PART_LOW_IDX / 100 part_low_idx, 
                F_PART_INIT_IDX / 100 part_init_idx, 
                F_PART_IDX / 100 part_idx, 
                F_PART_MA5_IDX / 100 part_ma5_idx, 
                F_PART_MA20_IDX / 100 part_ma20_idx 
            from ( 
                select  a.F_DATA_DAY, a.F_PART_CODE, b.f_part_name, 
                    a.F_CHG_TYPE, a.F_PART_CHG, a.F_PART_VOL, 
                    a.F_PART_HIGH_IDX, a.F_PART_LOW_IDX, a.F_PART_INIT_IDX, 
                    a.F_PART_IDX, a.F_PART_MA5_IDX, a.F_PART_MA20_IDX 
                from t_index_his_day a, t_part b 
                where a.f_part_code = b.f_part_code 
                    and b.f_part_name = '{1}' 
                order by a.F_DATA_DAY desc 
            ) 
            where rownum <= {0} order by F_DATA_DAY asc";

        #endregion

            #region 거래량
        
        this.queryQuantityToday = @"select 
                a.F_DATA_DAY, 
                a.F_DATA_TIME, 
                a.F_PART_CODE, 
                b.f_part_name, 
                a.F_CHG_TYPE, 
                a.F_PART_CHG / 100 part_chg, 
                a.F_PART_HIGH_IDX / 100 part_high_idx, 
                a.F_PART_LOW_IDX / 100 part_low_idx, 
                a.F_PART_INIT_IDX / 100 part_init_idx, 
                a.F_PART_IDX / 100 part_idx, 
                F_PART_VOL part_vol 
            from t_index_his_5M a, t_part b 
            where a.f_part_code = b.f_part_code 
                and b.f_part_name = '{0}'
                and a.f_data_day = (select max(open_day) from v_open_day) 
            order by a.F_DATA_DAY, a.F_DATA_TIME";


            this.queryQuantityLast = @"select 
                F_DATA_DAY, 
                F_PART_CODE, 
                f_part_name part_name, 
                F_CHG_TYPE chg_type, 
                f_part_vol part_vol, 
                F_PART_CHG / 100 part_chg, 
                F_PART_HIGH_IDX / 100 part_high_idx, 
                F_PART_LOW_IDX / 100 part_low_idx, 
                F_PART_INIT_IDX / 100 part_init_idx, 
                F_PART_IDX / 100 part_idx, 
                F_PART_MA5_IDX / 100 part_ma5_idx, 
                F_PART_MA20_IDX / 100 part_ma20_idx 
            from ( 
                select  a.F_DATA_DAY, a.F_PART_CODE, b.f_part_name, 
                    a.F_CHG_TYPE, a.F_PART_CHG, a.F_PART_VOL, 
                    a.F_PART_HIGH_IDX, a.F_PART_LOW_IDX, a.F_PART_INIT_IDX, 
                    a.F_PART_IDX, a.F_PART_MA5_IDX, a.F_PART_MA20_IDX 
                from t_index_his_day a, t_part b 
                where a.f_part_code = b.f_part_code 
                    and b.f_part_name = '{1}' 
                order by a.F_DATA_DAY desc 
            ) 
            where rownum <= {0}  order by F_DATA_DAY asc";

    }

    #endregion

        }
}
