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


        internal INDUSTRY_PAN(국내시장종류 recvDataType, string recvStockCode)
        {
            this.mDataType = recvDataType;
            this.mDataCode = recvStockCode;
        }

        국내시장종류 mDataType;

        string mDataCode = String.Empty;

        #region "쿼리"

        string queryKOSPI = @"SELECT b.f_part_name, 
		round(a.f_part_idx / 100, 2) part_idx, a.f_chg_type chg_type, round(a.f_part_chg / 100, 2) part_chg, 
		round((a.f_part_chg / decode(a.f_chg_type, '+', a.f_part_idx - a.f_part_chg, '-', a.f_part_idx + a.f_part_chg)) * 100, 2) rate 
		FROM t_index a, t_part b 
		WHERE a.f_part_code = b.f_part_code 
		and b.f_part_name = '{0}'";

        string queryKOSDAQ = @"SELECT b.f_part_name, 
		round(a.f_part_idx / 100, 2) part_idx, a.f_chg_type chg_type, round(a.f_part_chg / 100, 2) part_chg, 
		round((a.f_part_chg / decode(a.f_chg_type, '+', a.f_part_idx - a.f_part_chg, '-', a.f_part_idx + 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 b.f_part_name = '{0}'";

        #endregion


        public override IDataRequest buildData()
        {

            string bufQuery = "";

            switch (mDataType)
            {
                case 국내시장종류.KOSPI:
                    bufQuery = string.Format(queryKOSPI, mDataCode);
                    break;
                case 국내시장종류.KOSDAQ:
                    bufQuery = string.Format(queryKOSDAQ, mDataCode);
                    break;
            }

            mRequestQuery.Add("", bufQuery);

            return this;
        }
    }
}
