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

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

            if (recvDataType == DBDefine.봉차트세부종목.거래량)
            {
                throw new Exception("선물은 거래량 쿼리가 없음.");
            }

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

        this.queryForecastToday = @"SELECT 
                '선물' name, 
                part_idx part_idx, 
                chg_type, 
                ABS(part_chg) part_chg, 
                round(part_chg / decode(chg_type, '+', (part_idx / 100) - (part_chg / 100), '-', (part_idx / 100) + (part_chg / 100), 1), 2) rate 
            FROM ( 
                SELECT decode(a.f_fo_price,0, b.F_JUN_LAST_PRICE, a.f_fo_price) part_idx,                    
      decode(a.f_fo_price, 0, 0, (a.f_fo_price - b.F_JUN_LAST_PRICE)/100) part_chg,
      decode(a.f_fo_price, 0, ' ', decode(sign(a.f_fo_price -b.F_JUN_LAST_PRICE),1,'+',-1,'-',0,' ')) chg_type
 FROM t_sunmul_online a, t_sunmul_batch b
WHERE a.f_stock_code = b.f_stock_code
  AND a.f_stock_seq = 1
  AND b.f_market_date = (select max(OPEN_DAY) from v_open_day)
  AND b.F_MONTH_GUBUN = '1'
            )";

            this.queryForecastLast = @"select 
        F_DATA_DAY, 
		chg_type,  
        part_chg, 
		part_high_idx / 100 part_high_idx, 
        part_low_idx / 100 part_low_idx, 
        part_init_idx / 100 part_init_idx, 
		part_idx / 100 part_idx, 
        part_ma5_idx / 100 part_ma5_idx, 
        part_ma20_idx / 100 part_ma20_idx 
		FROM( 
            select F_DATA_DAY, F_CHG_TYPE chg_type, F_PART_CHG part_chg, 
			F_PART_HIGH_IDX part_high_idx, F_PART_LOW_IDX part_low_idx, F_PART_INIT_IDX part_init_idx, 
			F_PART_IDX part_idx, F_PART_MA5_IDX part_ma5_idx, F_PART_MA20_IDX part_ma20_idx 
			from T_SUNMUL_HIS_DAY 
			order by f_data_day desc) 
	where rownum <= {0} order by F_DATA_DAY asc";

            #endregion
            
            #region 지수

        this.queryIndexNow = @"SELECT 
                '선물' name, 
                part_idx part_idx, 
                chg_type, 
                ABS(part_chg) part_chg, 
                ABS(round(part_chg / decode(chg_type, '+', (part_idx / 100) - (part_chg / 100), '-', (part_idx / 100) + (part_chg / 100), 1), 2)) rate 
            FROM ( 
                SELECT decode(a.f_curr_price,0, b.F_JUN_LAST_PRICE/100, a.f_curr_price/100) part_idx, a.F_NET_VOL, a.f_out_vol,  a.F_NET_TURNOVER,
                decode(a.f_curr_price, 0, 0, (a.f_curr_price - b.F_JUN_LAST_PRICE*100)/100) part_chg,
                decode(a.f_curr_price, 0, ' ', decode(sign(a.f_curr_price -b.F_JUN_LAST_PRICE*100),1,'+',-1,'-',0,' ')) chg_type
           FROM t_sunmul_online a, t_sunmul_batch b
          WHERE a.f_stock_code = b.f_stock_code
            AND a.f_stock_seq = 1
            AND b.f_market_date = (select max(OPEN_DAY) from v_open_day)
            AND b.F_MONTH_GUBUN = '1'
            )";

            this.queryIndexToday = @"select 
                a.F_DATA_DAY, 
                a.F_DATA_TIME, 
                a.F_PART_IDX/100, 
                a.F_CHG_TYPE, 
                a.F_PART_CHG, 
                a.F_PART_HIGH_IDX/100, 
                a.F_PART_LOW_IDX/100, 
                a.F_PART_INIT_IDX/100 
            from t_sunmul_his_5M a 
            where 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, 
                chg_type, 
                part_chg, 
                part_high_idx/100, 
                part_low_idx/100, 
                part_init_idx/100, 
                part_idx/100, 
                part_ma5_idx/100, 
                part_ma20_idx/100 
            FROM ( 
                select 
                    F_DATA_DAY, 
                    F_CHG_TYPE chg_type, 
                    F_PART_CHG part_chg, 
                    F_PART_HIGH_IDX part_high_idx, 
                    F_PART_LOW_IDX part_low_idx, 
                    F_PART_INIT_IDX part_init_idx, 
                    F_PART_IDX part_idx, 
                    F_PART_MA5_IDX part_ma5_idx, 
                    F_PART_MA20_IDX part_ma20_idx 
                from T_SUNMUL_HIS_DAY 
                order by f_data_day desc 
            ) 
            where rownum <= {0} order by F_DATA_DAY asc";

            #endregion

            #region 거래량

            this.queryQuantityToday = @"";


            this.queryQuantityLast = @"";

    }

    #endregion

        }
}
