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

        public Square20(국내시장종류 recvMarketType)
        {
            this.mMarketType = recvMarketType;
        }

        private 국내시장종류 mMarketType;

        /// <summary>
        /// 금일 데이터 쿼리
        /// </summary>
         string queryKOSPI = @"select b.f_part_name, a.F_PART_IDX/100 part_idx, a.F_CHG_TYPE, a.F_PART_CHG/100 part_chg, 
		round(a.f_part_chg / decode(a.f_chg_type, '+', (a.f_part_idx / 100) - (a.f_part_chg / 100), 
			'-', (a.f_part_idx / 100) + (a.f_part_chg / 100)), 2) rate 
		from t_index a, t_part b 
	where a.f_part_code = b.f_part_code 
	and a.f_part_code in('013', '009', '011', '016', '018', 
		'021', '008', '020', '007', '012','015', '005', '014', '006', '019') order by a.f_part_code";


        string queryKOSDAQ = @"select b.f_part_name, a.F_PART_IDX/100 part_idx, a.F_CHG_TYPE, a.F_PART_CHG/100 part_chg, 
		round(a.f_part_chg / decode(a.f_chg_type, '+', (a.f_part_idx / 100) - (a.f_part_chg / 100), 
			'-', (a.f_part_idx / 100) + (a.f_part_chg / 100)), 2) rate 
		from t_kosdaq_index a, t_kosdaq_part b 
	where a.f_part_code = b.f_part_code 
	and a.f_part_code in('066', '159', '154', '160', '065', 
		'031', '029', '070', '026', '024', 
		'041', '056', '153', '027', '062') order by a.f_part_code";

        public override IDataRequest buildData()
        {

            string bufQuery = "";

            switch (this.mMarketType)
            {
                case 국내시장종류.KOSPI:
                    bufQuery = queryKOSPI;
                    break;
                case 국내시장종류.KOSDAQ:
                    bufQuery = queryKOSDAQ;
                    break;
            }

            mRequestQuery.Add("", bufQuery);

            return this;
        }
    }
}
