using System;
using Cute;
using LitJson;

namespace Wizard;

public class LoadTask : BaseTask
{
	public enum AccountDeleteStatus
	{
		NONE,
		CAN_RESET_RESERVE,
		CAN_NOT_RESET_RESERVE
	}

	public class LoadTaskParam : BaseParam
	{
		public string carrier = "";

		public string card_master_hash = "";
	}

	public LoadDetail LoadDetailInstance { get; private set; }

	public AccountDeleteStatus DeleteStatus { get; private set; }

	public string DeleteLimitDate { get; private set; }

	public LoadTask()
	{
		base.type = ApiType.Type.Load;
	}

	public void SetParameter()
	{
		LoadTaskParam loadTaskParam = new LoadTaskParam();
		loadTaskParam.carrier = Toolbox.DeviceManager.GetCarrier();
		loadTaskParam.card_master_hash = CardMasterLocalFileUtility.GetCardMasterHash();
		base.Params = loadTaskParam;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		JsonData jsonData = base.ResponseData["data"];
		if (jsonData.Keys.Contains("account_delete_reservation_status"))
		{
			DeleteStatus = (AccountDeleteStatus)jsonData["account_delete_reservation_status"].ToInt();
			double timeLimitUnixTime = ConvertTime.DateTimeToUnixTime(DateTime.Parse(jsonData["account_delete_reservation_cancelable_deadline"].ToString()));
			double nowUnixTime = base.ResponseData["data_headers"]["servertime"].ToDouble();
			DeleteLimitDate = GetLateTime(timeLimitUnixTime, nowUnixTime);
			return num;
		}
		LoadDetailInstance = new LoadDetail();
		Data.Load.data = LoadDetailInstance;
		Data.Load.data.ConvertJsonData(base.ResponseData);
		return num;
	}

	private static string GetLateTime(double timeLimitUnixTime, double nowUnixTime)
	{
		double num = timeLimitUnixTime - nowUnixTime;
		if (num < 0.0)
		{
			num = 0.0;
		}
		int num2 = 0;
		if (num >= 86400.0)
		{
			num2 = (int)(num / 86400.0);
		}
		int num3 = 0;
		if (num >= 3600.0)
		{
			num3 = (int)(num / 3600.0);
			num3 %= 24;
		}
		int num4 = 0;
		if (num >= 60.0)
		{
			num4 = (int)(num / 60.0);
			num4 %= 60;
		}
		if (num >= 86400.0)
		{
			return Data.SystemText.Get("System_0065", num2.ToString(), num3.ToString(), num4.ToString());
		}
		if (num >= 3600.0)
		{
			return Data.SystemText.Get("System_0066", num3.ToString(), num4.ToString());
		}
		return Data.SystemText.Get("System_0067", num4.ToString());
	}
}
