using LitJson;

namespace Wizard.Lottery;

public class LotteryMissionData
{
	public int MissionId { get; private set; }

	public string MissionTitle { get; private set; }

	public UserGoods.Type UserGoodsType { get; private set; }

	public int ItemId { get; private set; }

	public int ItemCount { get; private set; }

	public RemainTime StartTime { get; private set; }

	public RemainTime EndTime { get; private set; }

	public int MissionCurrent { get; private set; }

	public int MissionMax { get; private set; }

	public bool IsCleared { get; private set; }

	public bool IsTimeOver { get; private set; }

	public float MissionRatio
	{
		get
		{
			if (MissionMax == 0)
			{
				return 0f;
			}
			return (float)MissionCurrent / (float)MissionMax;
		}
	}

	public LotteryMissionData(JsonData json, double serverTime)
	{
		MissionId = json["mission_id"].ToInt();
		ItemId = json["reward_detail_id"].ToInt();
		UserGoodsType = (UserGoods.Type)json["reward_type"].ToInt();
		ItemCount = json["reward_number"].ToInt();
		MissionTitle = json["mission_name"].ToString();
		MissionCurrent = json["total_count"].ToInt();
		MissionMax = json["require_number"].ToInt();
		IsCleared = json["is_achieved"].ToInt() == 1;
		IsTimeOver = json["is_failed"].ToInt() == 1;
		string endTime = ConvertTime.UnixTimeToDateTime(json["start_time"].ToInt()).ToString();
		string endTime2 = ConvertTime.UnixTimeToDateTime(json["end_time"].ToInt()).ToString();
		StartTime = new RemainTime(endTime, serverTime);
		EndTime = new RemainTime(endTime2, serverTime);
	}
}
