using LitJson;
using Wizard;
using Wizard.Story;

public class StorySectionData
{
	private static readonly string FORMAT_STORY_SECTION_NO = "story_section_no_{0:D2}";

	public const int WAZAWAI_SECTION_ID = 1;

	private const int WAZAWAI_FINAL_SECTION_ID = 2;

	public const int OUKOKU_KIKAN_SECTION_ID = 9003;

	public const int SHUKUSEI_HEN_KOUHEN_SECTION_ID = 20;

	public int Id { get; }

	public int AllStoryOrderId { get; }

	public string NameNo { get; }

	public string Name { get; }

	public string ImageName { get; }

	public string OffStateButtonTextureName { get; }

	public string OnStateButtonTextureName { get; }

	public bool IsLeaderSelect { get; }

	public bool IsFinish { get; }

	public bool IsUnderMaintenance { get; }

	public int ReleasedCharaCount { get; }

	public int FinishedCharaCount { get; }

	public int BackGroundId { get; }

	public StoryApiType StoryApiType { get; }

	public bool IsNew { get; }

	public bool IsSpoiler { get; }

	public string SpoilerMessage { get; }

	public UIManager.ViewScene ChapterSelectionView { get; }

	public bool IsPlayAnotherEndingAppearanceAnimation { get; }

	public bool IsTutorialCategory => Id == StorySection.TUTORIAL_SECTION_ID;

	public bool IsTutorial
	{
		get
		{
			if (IsTutorialCategory)
			{
				return !IsFinish;
			}
			return false;
		}
	}

	public bool IsTutorialReplay
	{
		get
		{
			if (IsTutorialCategory)
			{
				return IsFinish;
			}
			return false;
		}
	}

	public bool IsExistExtraBackGround()
	{
		if (Id != 2 && Id != 9003)
		{
			return Id == 20;
		}
		return true;
	}

	public StorySectionData(JsonData jsonData)
	{
		Id = jsonData["section_id"].ToInt();
		AllStoryOrderId = jsonData["all_story_order_id"].ToInt();
		NameNo = GetNameNoText(jsonData);
		Name = GetNameText(jsonData);
		ImageName = jsonData["image_name"].ToString();
		OffStateButtonTextureName = GetOffStateButtonTextureName(jsonData);
		OnStateButtonTextureName = GetOnStateButtonTextureName(jsonData);
		IsLeaderSelect = jsonData["is_leader_select"].ToBoolean();
		IsFinish = jsonData["is_finished"].ToBoolean();
		IsUnderMaintenance = jsonData["is_under_maintenance"].ToBoolean();
		ReleasedCharaCount = jsonData["released_chara_count"].ToInt();
		FinishedCharaCount = jsonData["finished_chara_count"].ToInt();
		BackGroundId = jsonData["back_ground_id"].ToInt();
		IsNew = jsonData["is_new"].ToBoolean();
		IsSpoiler = jsonData.GetValueOrDefault("is_spoiler", defaultValue: false);
		if (IsSpoiler)
		{
			SpoilerMessage = jsonData.GetValueOrDefault("spoiler_message", string.Empty);
		}
		StoryApiType = GetStoryApiType(jsonData["story_type_overwrite"].ToInt());
		ChapterSelectionView = GetChapterSelectionView(jsonData);
		IsPlayAnotherEndingAppearanceAnimation = jsonData["is_play_another_end_appearance_animation"].ToBoolean();
	}

	public StorySectionData(int id, int backgroundId, UIManager.ViewScene chapterSelectionView)
	{
		Id = id;
		BackGroundId = backgroundId;
		ChapterSelectionView = chapterSelectionView;
	}

	private static string GetNameNoText(JsonData jsonData)
	{
		int num = jsonData["section_id"].ToInt();
		string key = string.Format(FORMAT_STORY_SECTION_NO, num);
		return Data.Master.GetStorySectionTitleText(key);
	}

	private static string GetNameText(JsonData jsonData)
	{
		string key = jsonData["name"].ToString();
		return Data.Master.GetStorySectionTitleText(key);
	}

	private static string GetOffStateButtonTextureName(JsonData jsonData)
	{
		return jsonData["image_name"].ToString() + "_off";
	}

	private static string GetOnStateButtonTextureName(JsonData jsonData)
	{
		return jsonData["image_name"].ToString() + "_on";
	}

	private static UIManager.ViewScene GetChapterSelectionView(JsonData jsonData)
	{
		if (jsonData["chapter_select_type"].ToInt() != 2)
		{
			return UIManager.ViewScene.AreaSelect;
		}
		return UIManager.ViewScene.StoryChapterSelectionFlowChart;
	}

	private static StoryApiType GetStoryApiType(int storyTypeOverwrite)
	{
		switch (storyTypeOverwrite)
		{
		case 0:
			return StoryApiType.None;
		case 1:
			return StoryApiType.MainStory;
		case 2:
			return StoryApiType.LimitedStory;
		case 3:
			return StoryApiType.EventStory;
		default:
			Debug.LogError("StorySectionのstory_type_overwriteに想定外の値が設定された");
			return StoryApiType.None;
		}
	}
}
