using LitJson;
using Wizard;

public class UserRank : HeaderData
{
	public class GrandMasterData
	{
		public int[] id = new int[3];

		public int[] periodNum = new int[3];

		public int[] masterPoint = new int[3];

		public int[] rankId = new int[3];

		public int targetMasterPoint;

		public int currentMasterPoint;
	}

	public const int GRAND_MASTER_PERIOD = 3;

	public const int MASTER_RANK_INDEX = 24;

	public int rank;

	public int battle_point;

	public int master_point;

	public int successive_win_number;

	public bool is_master_rank;

	public bool is_grand_master_rank;

	public GrandMasterData grandMasterData = new GrandMasterData();

	public UserPromotionMatch user_promotion_match = new UserPromotionMatch();

	public static bool IsGrandMasterAvailability { get; set; }

	public void Initialize(JsonData userRank, Format format)
	{
		rank = userRank["rank"].ToInt();
		battle_point = userRank["battle_point"].ToInt();
		master_point = userRank["master_point"].ToInt();
		successive_win_number = userRank["successive_win_number"].ToInt();
		is_master_rank = userRank["is_master_rank"].ToInt() != 0;
		is_grand_master_rank = userRank.GetValueOrDefault("is_grand_master_rank", 0) != 0;
		user_promotion_match.is_promotion = userRank["is_promotion"].ToInt() != 0;
		if (user_promotion_match.is_promotion)
		{
			user_promotion_match.match_count = userRank["user_promotion_match"]["match_count"].ToInt();
			user_promotion_match.battle_result = userRank["user_promotion_match"]["battle_result"].ToInt();
			user_promotion_match.win = userRank["user_promotion_match"]["win"].ToInt();
			user_promotion_match.lose = userRank["user_promotion_match"]["lose"].ToInt();
		}
		if (is_master_rank && format != Format.Crossover)
		{
			IsGrandMasterAvailability = false;
			if (userRank.Keys.Contains("target_grand_master_point"))
			{
				grandMasterData.targetMasterPoint = userRank["target_grand_master_point"].ToInt();
				IsGrandMasterAvailability = true;
			}
			if (userRank.Keys.Contains("current_grand_master_point"))
			{
				grandMasterData.currentMasterPoint = userRank["current_grand_master_point"].ToInt();
				IsGrandMasterAvailability = true;
			}
		}
		if (is_master_rank && format == Format.Crossover)
		{
			grandMasterData.currentMasterPoint = master_point;
		}
	}
}
