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

namespace Wizard;

public class PrereleasePurchaseInfo
{
	public int CurrentCount { get; private set; }

	public int LimitCount { get; private set; }

	public int PreReleasePointCurent { get; private set; }

	public int PreReleasePointLimit { get; private set; }

	public int TicketRupyCountCurrent { get; private set; }

	public int TicketRupyCountLimit { get; private set; }

	public int TicketRupyCountRemain
	{
		get
		{
			int a = LimitCount - CurrentCount;
			int b = TicketRupyCountLimit - TicketRupyCountCurrent;
			return Mathf.Min(a, b);
		}
	}

	public RemainTime RemainTime { get; private set; }

	public List<PurchaseRewardInfo> RewardsList { get; private set; }

	public bool IsCountLimitedPrerelease => LimitCount != 0;

	public PrereleasePurchaseInfo(JsonData json, double serverTime)
	{
		CurrentCount = json["purchase_count"].ToInt();
		LimitCount = json["purchase_limit_count"].ToInt();
		PreReleasePointCurent = json["pre_release_point"].ToInt();
		PreReleasePointLimit = json["pre_release_point_limit"].ToInt();
		TicketRupyCountCurrent = json["open_count_by_ticket_and_rupy"].ToInt();
		TicketRupyCountLimit = json["open_count_limit_by_ticket_and_rupy"].ToInt();
		RemainTime = new RemainTime(Prerelease.Instance.EndTime.ToString(), serverTime);
		RewardsList = new List<PurchaseRewardInfo>();
		JsonData jsonData = json["purchase_reward_list"];
		for (int i = 0; i < jsonData.Count; i++)
		{
			JsonData jsonData2 = jsonData[i];
			PurchaseRewardInfo purchaseRewardInfo = new PurchaseRewardInfo();
			JsonData jsonData3 = jsonData2["reward_list"];
			for (int j = 0; j < jsonData3.Count; j++)
			{
				ShopCommonRewardInfo item = new ShopCommonRewardInfo
				{
					Type = jsonData3[j]["reward_type"].ToInt(),
					UserGoodsId = jsonData3[j]["reward_detail_id"].ToLong(),
					Num = jsonData3[j]["reward_number"].ToInt()
				};
				purchaseRewardInfo.RewardInfoList.Add(item);
			}
			int num = jsonData2["purchase_count"].ToInt();
			purchaseRewardInfo.PurchaseNthText = Data.SystemText.Get("Shop_0205", num.ToString());
			purchaseRewardInfo.IsGet = jsonData2["is_received"].ToBoolean();
			RewardsList.Add(purchaseRewardInfo);
		}
	}

	public int GetAbleBuyPackNum()
	{
		return LimitCount - CurrentCount;
	}
}
