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

        internal theme_yesang_5dan(List<string> recvStockList)
        {
            this.mStockCodeList = recvStockList;
        }


        List<string> mStockCodeList = null;

        #region 쿼리
        //코스피 상단
        string query = @"SELECT 'KOSPI' gubun, b.f_stock_code STOCK_CODE, 
			b.f_stock_wanname STOCK_NAME, 
			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, 
			ABS(round(((a.f_fore_price - c.f_final_price) / c.f_final_price), 4) * 100) 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 c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
			AND b.f_stock_code = '{0}' 
			union 
			SELECT 'KOSDAQ' gubun, b.f_stock_code STOCK_CODE, 
			b.f_stock_wanname STOCK_NAME, 
			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, 
            ABS(round(((a.f_fore_price - c.f_final_price) / c.f_final_price), 4) * 100) 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 c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
			AND b.f_stock_code = '{0}' ";


   ////////////     string query = @"SELECT 'KOSPI' gubun, b.f_stock_code STOCK_CODE, 
			////////////b.f_stock_wanname STOCK_NAME, 
			////////////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, 
			////////////ABS(round(((a.f_fore_price - c.f_final_price) / c.f_final_price), 4) * 100) 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 c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
			////////////AND b.f_stock_code = '{0}' 
			////////////union 
			////////////SELECT 'KOSDAQ' gubun, b.f_stock_code STOCK_CODE, 
			////////////b.f_stock_wanname STOCK_NAME, 
			////////////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, 
   ////////////         ABS(round(((a.f_fore_price - c.f_final_price) / c.f_final_price), 4) * 100) 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 c.f_stock_code = a.f_stock_code AND c.f_final_price < > 0 
			////////////AND b.f_stock_code = '{0}' ";



        #endregion

        public override IDataRequest buildData()
        {


            mStockCodeList.ForEach(s =>
            {
                mRequestQuery.Add(s, string.Format(query, s));
            });


            return this;
        }
    }
}
