using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LolDataRequestLib.ResponseData
{
    class KDA선수 : IResponseData
    {


        public DataTable 디비데이터를데이터테이블로만듬()
        {

            DataTable 킬뎃어시테이블 = new DataTable(DBDefine.요청데이터분류.킬뎃어시.ToString());

            try
            {
                List<BsonValue> 선수데이터들 = DataManager.getInstance().경기데이터["participants"].AsBsonArray.ToList();

                킬뎃어시테이블.Columns.Add("팀");
                //픽리스트테이블.Columns.Add("포지션");
                킬뎃어시테이블.Columns.Add("선수닉네임");
                킬뎃어시테이블.Columns.Add("챔피언이름");
                킬뎃어시테이블.Columns.Add("킬");
                킬뎃어시테이블.Columns.Add("데스");
                킬뎃어시테이블.Columns.Add("어시스트");


                for (int i = 0; i < 선수데이터들.Count(); i++)
                {
                    BsonValue item = 선수데이터들[i];

                    DataRow bufRow = 킬뎃어시테이블.NewRow();

                    bufRow["팀"] = (DBDefine.팀구분)item["teamID"].ToInt32();

                    //bufRow["포지션"] = (DBDefine.라인구분)item["participantID"].AsInt32 + 1;
                    bufRow["선수닉네임"] = item["playerName"];
                    bufRow["챔피언이름"] = item["championName"];

                    try
                    {
                        bufRow["킬"] = item["stats"].AsBsonArray.Where(v => v["name"] == "CHAMPIONS_KILLED").ToList()[0]["value"];
                    }
                    catch(Exception ex)
                    {
                        bufRow["킬"] = "0";
                    }
                    try {
                        bufRow["데스"] = item["stats"].AsBsonArray.Where(v => v["name"] == "NUM_DEATHS").ToList()[0]["value"];
                    }
                    catch(Exception ex)
                    {
                        bufRow["데스"] = "0";
                    }
                    try
                    {
                        bufRow["어시스트"] = item["stats"].AsBsonArray.Where(v => v["name"] == "ASSISTS").ToList()[0]["value"];
                    }
                    catch (Exception ex)
                    {
                        bufRow["어시스트"] = "0";
                    } 

                    킬뎃어시테이블.Rows.Add(bufRow);
                }
            }
            catch(Exception ex) {
                Console.WriteLine(ex.ToString());
            }

            
            
            return 킬뎃어시테이블;

        }

    }
}
