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

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

        }

        국내시장종류 mDataType;

        #region 쿼리
        //코스피 상단
        string queryKOSPI = @"SELECT DISTINCT b.f_stock_code stock_code, 
			b.F_STOCK_WANNAME wanname, 
			a.f_fore_price curr_price, 
			ABS((a.f_fore_price - c.f_final_price)) net_chg, 
			CASE WHEN(a.f_fore_price - c.f_final_price) > 0 THEN '2' ELSE 
			CASE WHEN(a.f_fore_price - c.f_final_price) < 0 THEN '5' ELSE '3' END END CHG_TYPE, 
			b.F_LIST_NUM * a.f_fore_price sigachong, 
			round(((a.f_fore_price - c.f_final_price) / c.f_final_price)* 100, 2)   rate 
			FROM t_online1_call a, t_stock b, t_batch_day c 
			WHERE b.f_mkt_halt = 'N' 
			AND a.f_stock_code = b.f_stock_code 
			AND a.f_fore_price <> 0 
            AND b.f_sect_code in ( 'ST', 'FS','DR', 'RT', 'IF')
			AND c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
			ORDER BY sigachong DESC";

////////        string queryKOSPI = @"SELECT DISTINCT b.f_stock_code stock_code, 
////////			b.F_STOCK_WANNAME wanname, 
////////			a.f_fore_price curr_price, 
////////			ABS((a.f_fore_price - c.f_final_price)) net_chg, 
////////			CASE WHEN(a.f_fore_price - c.f_final_price) > 0 THEN '2' ELSE 
////////			CASE WHEN(a.f_fore_price - c.f_final_price) < 0 THEN '5' ELSE '3' END END CHG_TYPE, 
////////			b.F_LIST_NUM * a.f_fore_price sigachong, 
////////			ABS(round(((a.f_fore_price - c.f_final_price) / c.f_final_price)* 100, 2))   rate 
////////			FROM t_online1 a, t_stock b, t_batch_day c 
////////			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_fore_price <> 0 
////////AND b.f_sect_code in ( 'ST', 'FS','DR', 'RT', 'IF')
////////			AND c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
////////			ORDER BY sigachong DESC";


        string queryKOSDAQ = @"SELECT DISTINCT b.f_stock_code stock_code, 
			b.F_STOCK_WANNAME wanname, 
			a.f_fore_price curr_price, 
			ABS((a.f_fore_price - c.f_final_price)) net_chg, 
			CASE WHEN(a.f_fore_price - c.f_final_price) > 0 THEN '2' ELSE 
			CASE WHEN(a.f_fore_price - c.f_final_price) < 0 THEN '5' ELSE '3' END END CHG_TYPE, 
			b.F_LIST_NUM * a.f_fore_price sigachong, 
			round(((a.f_fore_price - c.f_final_price) / c.f_final_price)* 100, 2) rate 
            FROM t_kosdaq_online1_call a, t_kosdaq_stock b, t_kosdaq_batch_day c 
			WHERE b.f_mkt_halt = 'N' 
			AND a.f_stock_code = b.f_stock_code 
			AND a.f_fore_price < > 0 
            AND b.f_sect_code in ( 'ST', 'FS','DR', 'RT', 'IF')
			AND c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
			ORDER BY sigachong DESC";

////        string queryKOSDAQ = @"SELECT DISTINCT b.f_stock_code stock_code, 
////			b.F_STOCK_WANNAME wanname, 
////			a.f_fore_price curr_price, 
////			ABS((a.f_fore_price - c.f_final_price)) net_chg, 
////			CASE WHEN(a.f_fore_price - c.f_final_price) > 0 THEN '2' ELSE 
////			CASE WHEN(a.f_fore_price - c.f_final_price) < 0 THEN '5' ELSE '3' END END CHG_TYPE, 
////			b.F_LIST_NUM * a.f_fore_price sigachong, 
////			round(((a.f_fore_price - c.f_final_price) / c.f_final_price)* 100, 2)   rate 
////            FROM t_kosdaq_online1 a, t_kosdaq_stock b, t_kosdaq_batch_day c 
////			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_fore_price < > 0 
////AND b.f_sect_code in ( 'ST', 'FS','DR', 'RT', 'IF')
////			AND c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
////			ORDER BY sigachong DESC";




        #endregion

        public override IDataRequest buildData()
        {


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


            return this;
        }
    }
}
