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

namespace MMoneyCoderSharp.DB
{
    /// <summary>
    /// </summary>
    internal class low_overtime_5dan : ADataObject
    {

        internal low_overtime_5dan(국내시장종류 recvDataType)
        {
            this.mDataType = recvDataType;

        }

        국내시장종류 mDataType;

        #region 쿼리
        //코스피 상단
        //        string queryKOSPI = @"SELECT DISTINCT b.f_stock_code stock_code, 
        //        b.F_STOCK_WANNAME wanname, 
        //		a.f_net_chg net_chg, 
        //        a.f_chg_type chg_type, 
        //		a.f_curr_price, 
        //		a.f_init_price, 
        //		a.f_high_price, 
        //		a.f_low_price, 
        //		round((a.f_net_chg / decode(a.f_chg_type, '4', -1 * (a.f_curr_price + a.f_net_chg), 
        //			'5', -1 * (a.f_curr_price + a.f_net_chg))) * 100, 2) rate 
        //		FROM t_overtime_sise a, t_stock b 
        //		WHERE b.f_mkt_halt = 'N' 
        //		AND b.f_stock_nickname is not null 
        //		AND a.f_stock_code = b.f_stock_code 
        //		AND a.f_curr_price < > 0 
        //AND b.f_sect_code in ( 'ST', 'FS','DR', 'RT', 'IF')
        //		AND a.f_chg_type in('4', '5') 
        //		ORDER BY rate";
        string queryKOSPI = @"SELECT DISTINCT b.f_stock_code stock_code, 
        b.F_STOCK_WANNAME wanname, 
		a.f_net_chg net_chg, 
        a.f_chg_type chg_type, 
		a.f_curr_price, 
		a.f_init_price, 
		a.f_high_price, 
		a.f_low_price, 
		round((a.f_net_chg / decode(a.f_chg_type, '4', -1 * (a.f_curr_price + a.f_net_chg), 
			'5', -1 * (a.f_curr_price + a.f_net_chg))) * 100, 2) rate 
		FROM t_overtime_sise a, t_stock b 
		WHERE b.f_mkt_halt = 'N' 
		AND a.f_stock_code = b.f_stock_code 
		AND a.f_curr_price < > 0 
        AND b.f_sect_code = 'ST'
		AND a.f_chg_type in('4', '5') 
		ORDER BY rate";



        //        string queryKOSDAQ = @"SELECT DISTINCT 
        //            b.f_stock_code stock_code, 
        //            b.F_STOCK_WANNAME wanname, 
        //			a.f_net_chg net_chg, 
        //            a.f_chg_type chg_type, 
        //			a.f_curr_price, 
        //			a.f_init_price, 
        //			a.f_high_price, 
        //			a.f_low_price, 
        //			round((a.f_net_chg / decode('4', a.f_curr_price + a.f_net_chg, 
        //				'5', a.f_curr_price + a.f_net_chg) * -1) * 100, 2) rate 
        //			FROM t_kosdaq_overtime_sise a, t_kosdaq_stock b 
        //			WHERE b.f_mkt_halt = 'N' 
        //			AND b.f_stock_nickname is not null 
        //            AND a.f_stock_code = b.f_stock_code 
        //			AND a.f_curr_price < > 0 
        //AND b.f_sect_code in ( 'ST', 'FS','DR', 'RT', 'IF')
        //			AND a.f_chg_type in('4', '5') 
        //			ORDER BY rate ";

        string queryKOSDAQ = @"SELECT DISTINCT 
            b.f_stock_code stock_code, 
            b.F_STOCK_WANNAME wanname, 
			a.f_net_chg net_chg, 
            a.f_chg_type chg_type, 
			a.f_curr_price, 
			a.f_init_price, 
			a.f_high_price, 
			a.f_low_price, 
			round((a.f_net_chg / decode('4', a.f_curr_price + a.f_net_chg, 
				'5', a.f_curr_price + a.f_net_chg) * -1) * 100, 2) rate 
			FROM t_kosdaq_overtime_sise a, t_kosdaq_stock b 
			WHERE b.f_mkt_halt = 'N' 
            AND a.f_stock_code = b.f_stock_code 
			AND a.f_curr_price < > 0 
            AND b.f_sect_code = 'ST'
			AND a.f_chg_type in('4', '5') 
			ORDER BY rate ";



        #endregion

        public override IDataRequest buildData()
        {


            switch (this.mDataType)
            {
                case 국내시장종류.KOSPI:
                    mRequestQuery.Add("", queryKOSPI);
                    break;
                case 국내시장종류.KOSDAQ:
                    mRequestQuery.Add("", queryKOSDAQ);
                    break;
            }


            return this;
        }
    }
}
