using MrWu.Debug;
using ObjectModel.Config;
using Server.DB.Sql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GameData;
using GameMessage;

namespace GameDAL
{
    public class ChongZhiShangPingDal
    {
        
        private static void ConvertData(DataTable dt,List<ChongZhiShangPing> shangPings)
        {
            if (dt == null || dt.Rows.Count <= 0) return;
            int len = dt.Rows.Count;
            for (int i = 0; i < len; i++)
            {
                var id = (int)dt.Rows[i]["id"];
                if (id <= 3) continue;
                ChongZhiShangPing temp = new ChongZhiShangPing();
                temp.id = id;
                temp.jiazhi = (int)dt.Rows[i]["jiazhi"];
                temp.GetJinBi = (long)dt.Rows[i]["deJinbi"];
                temp.GetCanSaiJuan = (int)dt.Rows[i]["deCanSaiJuan"];
                temp.GetFuHuoKa = (int)dt.Rows[i]["deFuhuoKa"];
                temp.GetZuanShi = (int)dt.Rows[i]["deZuanShi"];
                temp.GetHuiYuan = (int)dt.Rows[i]["deHuiYuan"];
                temp.PayZuanShi = (int)dt.Rows[i]["fuZuanshi"];
                temp.PayLiJuan = (int)dt.Rows[i]["fuLijuan"];
                temp.PayRMB = (int)dt.Rows[i]["fuRMB"];
                temp.PayHongBao = (int)dt.Rows[i]["payHongBao"];
                temp.Title = dt.Rows[i]["title"].ToString();
                Debug.Info($"id:{temp.id} title:{temp.Title} i:{temp.PayRMB}");
                //if (temp.PayLiJuan > 0) continue;
                shangPings.Add(temp);
            }
        }

        public static async Task<List<ChongZhiShangPing>> GetAllShangPingsAsync()
        {
            List<ChongZhiShangPing> result = new List<ChongZhiShangPing>();
            try
            {
                DataTable dt = await GameDB.Instance.selectDbAsync(dbbase.game2018, "tbChongZhiShangPing");
                ConvertData(dt,result);
            }
            catch (Exception e)
            {
                Debug.Error($"获取所有充值商品出错 msg:{e.Message},code{e.StackTrace}");
            }
            return result;
        }

    }
}
