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 Grid13 : ADataObject
    {
     
        /// <summary>
        /// 금일 데이터 쿼리
        /// </summary>
         string queryToday = @"select '차익' name,
		round(((F_CCON_BUY_W_AMT + F_CCON_BUY_J_AMT) - (F_CCON_SELL_W_AMT + F_CCON_SELL_J_AMT)) / 100000000) part_idx
		from t_pgm_tot
		union
		select '비차익' name,
		round(((F_BCON_BUY_W_AMT + F_BCON_BUY_J_AMT) - (F_BCON_SELL_W_AMT + F_BCON_SELL_J_AMT)) / 100000000) part_idx
		from t_pgm_tot
		union
		select '순매수' name,
		round((((F_BCON_BUY_W_AMT + F_BCON_BUY_J_AMT) - (F_BCON_SELL_W_AMT + F_BCON_SELL_J_AMT)) +
			((F_CCON_BUY_W_AMT + F_CCON_BUY_J_AMT) - (F_CCON_SELL_W_AMT + F_CCON_SELL_J_AMT))) / 100000000) part_idx
		from t_pgm_tot
		union
		SELECT '코스피200' name, decode(f_chg_type, '-', (f_part_idx / 100) * -1, f_part_idx / 100) part_idx
		FROM T_200_INDEX
		WHERE f_part_code = '029'
		union
		SELECT '선물' name, decode(chg_type, '-', part_idx * -1, part_idx) part_idx
		FROM(SELECT f_curr_price / 100 part_idx,
			decode(sign(f_curr_price - f_base_price), 1, '+', -1, '-', 0, ' ') chg_type
			FROM t_sunmul_online
			WHERE f_stock_code = (select f_stock_code from t_sunmul_batch
	where f_market_date = (select max(f_market_date)
		from t_sunmul_batch)
		and substr(f_stock_code, 4, 1) = '1'
		and F_MONTH_GUBUN = '1')
		)
		union
		select '베이시스' name,
		b.part_idx - a.part_idx part_idx
		from
		(SELECT '코스피200' name, decode(f_chg_type, '-', (f_part_idx / 100) * -1, f_part_idx / 100) part_idx
			FROM T_200_INDEX
			WHERE f_part_code = '029') A,
		(SELECT '선물' name, decode(chg_type, '-', part_idx * -1, part_idx) part_idx
			FROM(SELECT f_curr_price / 100 part_idx,
				decode(sign(f_curr_price - f_base_price), 1, '+', -1, '-', 0, ' ') chg_type
				FROM t_sunmul_online
				WHERE f_stock_code = (select f_stock_code from t_sunmul_batch
	where f_market_date = (select max(f_market_date)
		from t_sunmul_batch)
		and substr(f_stock_code, 4, 1) = '1'
		and F_MONTH_GUBUN = '1')
			)) B";

        public override IDataRequest buildData()
        {

            string bufQuery = "";

            bufQuery += String.Format(queryToday);

            mRequestQuery.Add("", bufQuery);

            return this;
        }
    }
}
