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 EXCHANGE_PAN : ADataObject
    {
     
        internal EXCHANGE_PAN(원환율 recvDataType)
        {
            this.mDataType = recvDataType;
        }

        원환율 mDataType;

        #region "쿼리"

        string queryDOLLOR = @"SELECT a.f_input_code stock_code, '원/달러' stock_name, 
		a.f_curr_price curr_price, a.f_net_chg net_chg, a.f_chg_type, 
		round((a.f_net_chg / decode(a.f_chg_type, '+', (a.f_curr_price - f_net_chg), '-', (a.f_curr_price + f_net_chg), 1)) * 100, 2) rate 
		FROM t_input_index a, t_input_code b 
		WHERE a.f_input_code = b.f_input_code 
		AND a.f_input_code = 'A09'";

        string queryJPY = @"SELECT a.f_input_code stock_code, '원/엔' stock_name, 
		a.f_curr_price curr_price, a.f_net_chg net_chg, a.f_chg_type, 
		round((a.f_net_chg / decode(a.f_chg_type, '+', (a.f_curr_price - f_net_chg), '-', (a.f_curr_price + f_net_chg), 1)) * 100, 2) rate 
		FROM t_input_index a, t_input_code b 
		WHERE a.f_input_code = b.f_input_code 
		AND a.f_input_code = 'A10'";

        string queryYUAN = @"SELECT a.f_input_code stock_code, '원/위엔' stock_name, 
		a.f_curr_price curr_price, abs(a.f_net_chg) net_chg, a.f_chg_type, 
		round((a.f_net_chg / decode(a.f_chg_type, '+', (a.f_curr_price - f_net_chg), '-', (a.f_curr_price + f_net_chg), 1)) * 100, 2) rate 
		FROM t_input_index a, t_input_code b 
		WHERE a.f_input_code = b.f_input_code 
		AND a.f_input_code = 'A90'";

        string queryEURO = @"SELECT a.f_input_code stock_code, '원/유로' stock_name, 
		a.f_curr_price curr_price, a.f_net_chg net_chg, a.f_chg_type, 
		round((a.f_net_chg / decode(a.f_chg_type, '+', (a.f_curr_price - f_net_chg), '-', (a.f_curr_price + f_net_chg), 1)) * 100, 2) rate 
		FROM t_input_index a, t_input_code b 
		WHERE a.f_input_code = b.f_input_code 
		AND a.f_input_code = 'A91'";

        #endregion

        public override IDataRequest buildData()
        {

            string bufQuery = "";

            switch (mDataType)
            {
                case 원환율.원위엔:
                    bufQuery = queryYUAN;
                    break;
                case 원환율.원달러:
                    bufQuery = queryDOLLOR;
                    break;
                case 원환율.원엔:
                    bufQuery = queryJPY;
                    break;
                case 원환율.원유로:
                    bufQuery = queryEURO;
                    break;
            }

            mRequestQuery.Add("", bufQuery);

            return this;
        }
    }
}
