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

        public Stick21(섹터지수막대그래프분류 recvDataType)
        {
            this.mDataType = recvDataType;
        }

        private 섹터지수막대그래프분류 mDataType;

        /// <summary>
        /// 금일 데이터 쿼리
        /// </summary>
         string queryKOSPI = @"select 
                b.f_part_name, 
                a.F_PART_IDX/100, 
                a.F_CHG_TYPE, 
                a.F_PART_CHG/100, 
                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', '007', '015', '005') 
            order by a.f_part_code";


        string queryKOSDAQ = @"select 
                b.f_part_name, 
                a.F_PART_IDX/100, 
                a.F_CHG_TYPE, 
                a.F_PART_CHG/100, 
                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('159', '160', '066', '154', '065', '031', '029', '070', '024', '153') 
            order by a.f_part_code";

        string queryDOW = @"select 
                a.f_input_name  name, 
                round(b.f_last,2) part_idx, 
                b.f_sign chg_type, 
                ABS(round(b.f_diff, 2))  part_chg, 
                round(b.f_rate, 2) rate 
            from t_world_ix_eq_master a, t_world_ix_eq_sise b 
            where a.f_symb = b.f_symb 
                and a.f_symb in('DJI@DJINET', 'DJI@DJUSAU', 'DJI@DJUSCH', 'DJI@DJUSNF', 'DJI@DJUSCN', 'DJI@DJT', 'DJI@DJU', 'DJI@DJUSFB', 'DJI@DJUSCFT', 'DJI@DJUSEE')";


        string queryNASDAQ = @"select 
                a.f_input_name name, 
                round(b.f_last,2) part_idx, 
                b.f_sign chg_type, 
                ABS(round(b.f_diff, 2))  part_chg, 
                round(b.f_rate, 2) rate 
            from t_world_ix_eq_master a, t_world_ix_eq_sise b 
            where a.f_symb = b.f_symb 
                and a.f_symb in('NAS@CXBT', 'NAS@NDX', 'NAS@NQSSSE', 'NAS@IXBK', 'NAS@IXIS', 'NAS@IXUT', 'NAS@IXK', 'NAS@NBI', 'NAS@IXF', 'NAS@NDXT')";


        string querySNP = @"select 
                a.f_input_name name, 
                round(b.f_last,2) part_idx, 
                b.f_sign chg_type, 
                ABS(round(b.f_diff, 2))  part_chg, 
                round(b.f_rate, 2) rate 
            from t_world_ix_eq_master a, t_world_ix_eq_sise b 
            where a.f_symb = b.f_symb 
                and a.f_symb in('SPI@S5ENRS', 'SPI@S5RLST', 'SPI@S5AUCO', 'SPI@S5INFT', 'SPI@S5COND', 'SPI@S5INSU', 'SPI@S5ELUTX', 'SPI@S5HLTH', 'SPI@S5FINL', 'SPI@S5TELS')";


        public override IDataRequest buildData()
        {

            string bufQuery = "";

            switch (this.mDataType)
            {
                case 섹터지수막대그래프분류.코스피:
                    bufQuery = queryKOSPI;
                    break;
                case 섹터지수막대그래프분류.코스닥:
                    bufQuery = queryKOSDAQ;
                    break;
                case 섹터지수막대그래프분류.다우:
                    bufQuery = queryDOW;
                    break;
                case 섹터지수막대그래프분류.나스닥:
                    bufQuery = queryNASDAQ;
                    break;
                case 섹터지수막대그래프분류.SNP:
                    bufQuery = querySNP;
                    break;
            }

            mRequestQuery.Add("", bufQuery);

            return this;
        }
    }
}
