using System;
using System.Collections.Generic;
using LitJson;

namespace Wizard.Lottery;

public class LotteryInfoTask : BaseTask
{
	public class LotteryInfoData
	{
		public List<LotteryRewardData> LotteryRewardList;

		public List<LotteryMissionData> LotteryMissionList;

		public List<LotteryRewardData> MissionRewardList;

		public LotteryRewardData BigChanceReward;

		public int CampaignId { get; private set; }

		public string InfoUrl { get; private set; }

		public DateTime StartTime { get; private set; }

		public DateTime OpenTime { get; private set; }

		public DateTime EndTime { get; private set; }

		public DateTime CloseTime { get; private set; }

		public DateTime BigChanceOpenTime { get; private set; }

		public DoubleChanceData DoubleChanceReward { get; private set; }

		public LotteryMissionData BigChanceMission { get; private set; }

		public string BannerFileName { get; private set; }

		public string BackGroundFileName { get; private set; }

		public string AnnounceId { get; private set; }

		public LotteryInfoData(JsonData responseData)
		{
			JsonData jsonData = responseData["data"];
			CampaignId = jsonData["campaign_id"].ToInt();
			InfoUrl = jsonData["info_url"].ToString();
			StartTime = DateTime.Parse(jsonData["start_time"].ToString());
			OpenTime = DateTime.Parse(jsonData["open_time"].ToString());
			EndTime = DateTime.Parse(jsonData["end_time"].ToString());
			CloseTime = DateTime.Parse(jsonData["close_time"].ToString());
			LotteryRewardList = new List<LotteryRewardData>();
			BannerFileName = jsonData["campaign_banner"].ToString();
			BackGroundFileName = jsonData["campaign_bg_image"].ToString();
			JsonData jsonData2 = jsonData["lottery_reward_list"];
			for (int i = 0; i < jsonData2.Count; i++)
			{
				LotteryRewardData item = new LotteryRewardData(jsonData2[i]);
				LotteryRewardList.Add(item);
			}
			if (jsonData.Keys.Contains("double_chance"))
			{
				JsonData data = jsonData["double_chance"];
				DoubleChanceReward = new DoubleChanceData(data);
			}
			if (jsonData.TryGetValue("big_chance", out var value) && jsonData.TryGetValue("big_chance_reward", out var value2))
			{
				BigChanceMission = new LotteryMissionData(value, responseData["data_headers"]["servertime"].ToDouble());
				BigChanceReward = new LotteryRewardData(value2);
				BigChanceOpenTime = DateTime.Parse(value["open_time"].ToString());
			}
			if (jsonData.TryGetValue("append_lottery_reward_list", out var value3))
			{
				JsonData jsonData3 = jsonData["append_mission_info_list"];
				Dictionary<int, LotteryMissionData> dictionary = new Dictionary<int, LotteryMissionData>();
				LotteryMissionList = new List<LotteryMissionData>();
				for (int j = 0; j < jsonData3.Count; j++)
				{
					LotteryMissionData lotteryMissionData = new LotteryMissionData(jsonData3[j], responseData["data_headers"]["servertime"].ToDouble());
					LotteryMissionList.Add(lotteryMissionData);
					dictionary.Add(lotteryMissionData.MissionId, lotteryMissionData);
				}
				MissionRewardList = new List<LotteryRewardData>();
				for (int k = 0; k < value3.Count; k++)
				{
					LotteryRewardData lotteryRewardData = new LotteryRewardData(value3[k]);
					MissionRewardList.Add(lotteryRewardData);
					lotteryRewardData.MissionData = dictionary[lotteryRewardData.MissionId];
				}
			}
			if (jsonData.TryGetValue("announce_id", out var value4))
			{
				AnnounceId = value4.ToString();
			}
		}
	}

	public class LotteryInfoTaskParam : BaseParam
	{
		public int campaign_id;
	}

	public LotteryInfoData Result { get; private set; }

	public LotteryInfoTask()
	{
		base.type = ApiType.Type.LotteryInfo;
	}

	public void SetParameter(int campaign_id)
	{
		LotteryInfoTaskParam lotteryInfoTaskParam = new LotteryInfoTaskParam();
		lotteryInfoTaskParam.campaign_id = campaign_id;
		base.Params = lotteryInfoTaskParam;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		Result = new LotteryInfoData(base.ResponseData);
		return num;
	}
}
