using System;
using LitJson;

namespace Wizard;

public class ShopExpirtyInfo
{
	public const string JSON_KEY = "sales_period_info";

	public int? SaleEndSeries { get; private set; }

	public string SaleEndTimeText { get; private set; }

	public bool IsEnableText => GetText() != null;

	public ShopExpirtyInfo(JsonData json)
	{
		if (json.Count != 0)
		{
			if (json.Keys.Contains("sales_period_time"))
			{
				SaleEndTimeText = ConvertTime.ToLocal(DateTime.Parse(json["sales_period_time"].ToString()));
			}
			if (json.Keys.Contains("sales_period_series"))
			{
				SaleEndSeries = json["sales_period_series"].ToInt();
			}
		}
	}

	public static ShopExpirtyInfo CreateNullData()
	{
		return new ShopExpirtyInfo(null);
	}

	public ShopExpirtyInfo(string dummyText)
	{
		SaleEndTimeText = dummyText;
	}

	public string GetText()
	{
		if (SaleEndSeries.HasValue)
		{
			return Data.SystemText.Get("Shop_0247", SaleEndSeries.Value.ToString());
		}
		if (SaleEndTimeText != null)
		{
			return Data.SystemText.Get("Shop_0245", SaleEndTimeText);
		}
		return null;
	}
}
