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 upper_5dan : ADataObject
    {

        internal upper_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, 
            round((a.f_net_chg / decode(a.f_chg_type, '1', (a.f_curr_price - a.f_net_chg), 
                '2', (a.f_curr_price - a.f_net_chg), 
                '3', (a.f_curr_price), 
                '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_online1 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 in ( 'ST', 'FS','DR', 'RT', 'IF')
            AND a.f_chg_type in('1', '2') 
            ORDER BY rate DESC";



        string queryKOSDAQ = @"SELECT DISTINCT b.f_stock_code stock_code, b.F_STOCK_WANNAME wanname, 
            a.f_net_chg net_chg, a.f_net_vol net_vol, a.F_NET_TURNOVER, a.f_chg_type chg_type, 
            b.F_LIST_NUM * A.F_CURR_PRICE sigachong, 
            a.f_init_price, 
            a.f_high_price, 
            a.f_low_price, 
            a.f_curr_price, 
            round((a.f_net_chg / decode(a.f_chg_type, '1', (a.f_curr_price - a.f_net_chg), 
                '2', (a.f_curr_price - a.f_net_chg), 
                '3', (a.f_curr_price), 
                '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_kosdaq_online1 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 in ( 'ST', 'FS','DR', 'RT', 'IF')
            AND a.f_chg_type in('1', '2') 
            ORDER BY rate DESC";




        #endregion

        public override IDataRequest buildData()
        {


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


            return this;
        }
    }
}
