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 Nxt_lower_5dan : Nxt_ADataObject
    {

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

        }

        국내시장종류 mDataType;

        #region 쿼리
        //코스피 상단
        string queryNXT_KOSPI = @"SELECT DISTINCT b.f_stock_code stock_code, b.F_STOCK_NAME wanname, 
                a.f_net_chg net_chg, a.f_chg_type chg_type, a.f_curr_price, 
                round((a.f_net_chg / case when a.f_chg_type = '1' then (a.f_curr_price - a.f_net_chg) 
                                      when a.f_chg_type = '2' then (a.f_curr_price - a.f_net_chg) 
                                      when a.f_chg_type = '3' then (a.f_curr_price) 
                                      when a.f_chg_type = '4' then -1*(a.f_curr_price + a.f_net_chg) 
                                      when a.f_chg_type = '5' then -1*(a.f_curr_price + a.f_net_chg) end) * 100, 2) rate  
            FROM n_online a, n_stock b
            WHERE b.f_stop_gubun = 'N'  
            AND a.f_stock_code = b.f_stock_code 
            AND a.f_curr_price != 0 
            AND a.f_chg_type in('4', '5') 
            ORDER BY rate";



        string queryNXT_KOSDAQ = @"SELECT DISTINCT b.f_stock_code stock_code, b.F_STOCK_NAME wanname, 
                a.f_net_chg net_chg, a.f_chg_type chg_type, a.f_curr_price, 
                round((a.f_net_chg / case when a.f_chg_type = '1' then (a.f_curr_price - a.f_net_chg) 
                                      when a.f_chg_type = '2' then (a.f_curr_price - a.f_net_chg) 
                                      when a.f_chg_type = '3' then (a.f_curr_price) 
                                      when a.f_chg_type = '4' then -1*(a.f_curr_price + a.f_net_chg) 
                                      when a.f_chg_type = '5' then -1*(a.f_curr_price + a.f_net_chg) end) * 100, 2) rate  
            FROM n_kosdaq_online a, n_kosdaq_stock b
            WHERE b.f_stop_gubun = 'N'  
            AND a.f_stock_code = b.f_stock_code 
            AND a.f_curr_price != 0 
            AND a.f_chg_type in('4', '5') 
            ORDER BY rate";




        #endregion

        public override Nxt_IDataRequest Nxt_buildData()
        {


            switch (this.mDataType)
            {
                case 국내시장종류.NXT_KOSPI:
                    Nxt_mRequestQuery.Add("", queryNXT_KOSPI);
                    break;
                case 국내시장종류.NXT_KOSDAQ:
                    Nxt_mRequestQuery.Add("", queryNXT_KOSDAQ);
                    break;
            }


            return this;
        }
    }
}
