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

        internal theme_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_curr_price CURR_PRICE, 
			a.f_net_chg NET_CHG, 
			a.f_chg_type CHG_TYPE, 
			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_curr_price < > 0 
			AND a.f_stock_code = b.f_stock_code 
			and b.f_stock_wanname in('{0}') 
			union 
			SELECT 'KOSDAQ' gubun, b.f_stock_code STOCK_CODE, 
			b.f_stock_wanname STOCK_NAME, 
			a.f_curr_price CURR_PRICE, 
			a.f_net_chg NET_CHG, 
			a.f_chg_type CHG_TYPE, 
			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_curr_price < > 0 
			AND a.f_stock_code = b.f_stock_code 
			and b.f_stock_wanname in('{0}')";




        #endregion

        public override IDataRequest buildData()
        {


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


            return this;
        }
    }
}
