using Wizard;

namespace Cute;

public class PaymentPCFinishTask : NetworkTask
{
	public class PaymentPCFinishParams : PostParams
	{
		public string product_id = "";

		public string steam_app_id = "";

		public string steam_order_id = "";

		public string steam_user_country = "";
	}

	private CuteNetworkDefine.ApiType apiType = CuteNetworkDefine.ApiType.PaymentPCFinish;

	public override string Url => $"{CustomPreference.GetApplicationServerURL()}{CuteNetworkDefine.ApiUrlList[apiType]}";

	public void SetParameter(string ProductId, string StreamAppID = "", string SteamOrderId = "")
	{
		PaymentPCFinishParams paymentPCFinishParams = new PaymentPCFinishParams();
		paymentPCFinishParams.product_id = ProductId;
		paymentPCFinishParams.steam_app_id = StreamAppID;
		paymentPCFinishParams.steam_order_id = SteamOrderId;
		paymentPCFinishParams.steam_user_country = PCPlatformSTEAM.Country;
		base.Params = paymentPCFinishParams;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		if (base.ResponseData["data"].Count > 0)
		{
			if (base.ResponseData["data"]["purchased_times_data"] != null)
			{
				Data.Load.data._userCrystalCount._lastPaymentItemBuyNumber = base.ResponseData["data"]["purchased_times_data"]["number_of_product_purchased"].ToInt();
				if (base.ResponseData["data"]["purchased_times_data"].Keys.Contains("csv_data_id"))
				{
					Data.Load.data._userCrystalCount._lastPaymentId = base.ResponseData["data"]["purchased_times_data"]["csv_data_id"].ToString();
				}
			}
			else
			{
				Data.Load.data._userCrystalCount._lastPaymentItemBuyNumber = 0;
				Data.Load.data._userCrystalCount._lastPaymentId = null;
			}
			Data.Load.data._userCrystalCount.total_crystal = base.ResponseData["data"]["after_free_crystal"].ToInt() + base.ResponseData["data"]["after_crystal"].ToInt();
			Data.Load.data._userCrystalCount.free_crystal = base.ResponseData["data"]["after_free_crystal"].ToInt();
			Data.Load.data._userCrystalCount.charge_crystal = base.ResponseData["data"]["after_crystal"].ToInt();
			MyPageMenu.Instance.UpdateCrystalCount();
			if (CreateItemList.GetInstance() != null)
			{
				CreateItemList.GetInstance().UpdateCrystalCount();
			}
			if (GachaUI.GetInstance() != null)
			{
				GachaUI.GetInstance().UpdateUserItemCount();
			}
		}
		return num;
	}
}
