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 타워파괴전체 : IResponseData
    {


        public DataTable 디비데이터를데이터테이블로만듬()
        {
           
            DataTable 타워철거테이블 = new DataTable(DBDefine.요청데이터분류.타워철거전체.ToString());


            타워철거테이블.Columns.Add("타워부서진팀");

            타워철거테이블.Columns.Add("경기시간(초)");
            타워철거테이블.Columns.Add("파괴된라인");
            타워철거테이블.Columns.Add("터렛티어");
            타워철거테이블.Columns.Add("타워종류");
            타워철거테이블.Columns.Add("타워위치");
            타워철거테이블.Columns.Add("넥서스타워");

            if (DataManager.getInstance().건물데이터 == null)
            {
                return 타워철거테이블;
            }

            BsonDocument dd = DataManager.getInstance().건물데이터.DeepClone().AsBsonDocument;

            dd.Remove("sequenceIndex");

            List<BsonElement> bufStructDataList = dd.ToList();


            //Console.WriteLine("타워파괴전체.cs : 시작");

            foreach (BsonElement item in bufStructDataList)
            {
                
                DataRow bufRow = 타워철거테이블.NewRow(); 
                BsonDocument bufValue = item.Value.AsBsonDocument;

                //Console.WriteLine("타워파괴전체.cs 정보 : " + bufValue.ToString());

                //turretTier
                try
                {
                    bufRow["타워부서진팀"] = (DBDefine.팀구분)(bufValue["teamID"].ToInt32());                 
                    bufRow["경기시간(초)"] = (bufValue["gameTime"].ToInt32()) / 1000;

                    if (bufValue.AsBsonDocument.Contains("lane"))
                    {
                        bufRow["파괴된라인"] = bufValue["lane"].ToString();
                        if (bufValue.AsBsonDocument.Contains("turretTier"))
                        {
                            bufRow["터렛티어"] = bufValue["turretTier"].ToString();
                        }

                        if (bufValue.AsBsonDocument.Contains("nexusTurretName"))
                        {
                            bufRow["넥서스타워"] = bufValue["nexusTurretName"].ToString();
                            bufRow["타워위치"] = bufValue["position"].ToString();
                        }

                        bufRow["타워종류"] = bufValue["buildingType"].ToString();


                        타워철거테이블.Rows.Add(bufRow);
                    }
                }
                catch (Exception ex)
                {

                } 
            }

            return 타워철거테이블;

        }

    }
}
