using System.Collections.Generic;
using System.Xml;

namespace TeslaConsole.RedPlanet;

public class Scenario
{
	private string mKey;

	private string mName;

	private Dictionary<string, RPMap> mMaps = new Dictionary<string, RPMap>();

	private Dictionary<string, RPVehicle> mVehicles = new Dictionary<string, RPVehicle>();

	private Dictionary<string, string> mTimesOfDay = new Dictionary<string, string>();

	private Dictionary<string, string> mWeather = new Dictionary<string, string>();

	public string Key => mKey;

	public string Name => mName;

	public Dictionary<string, RPMap> Maps => mMaps;

	public Dictionary<string, RPVehicle> Vehicles => mVehicles;

	public Dictionary<string, string> TimesOfDay => mTimesOfDay;

	public Dictionary<string, string> Weather => mWeather;

	internal Scenario(XmlNode scenarioNode)
	{
		mKey = scenarioNode.Name;
		mName = scenarioNode.Attributes["name"].InnerText;
		List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
		foreach (XmlNode childNode in scenarioNode.ChildNodes)
		{
			if (childNode.Name == "invalid")
			{
				list.Add(new KeyValuePair<string, string>(childNode.Attributes["type"].InnerText, childNode.Attributes["key"].InnerText));
			}
		}
		foreach (RPMap value in RPConfig.Maps.Values)
		{
			if (!IsInvalid("map", value.Key, list))
			{
				mMaps.Add(value.Key, value);
			}
		}
		foreach (RPVehicle value2 in RPConfig.Vehicles.Values)
		{
			if (!IsInvalid("vehicle", value2.Key, list))
			{
				mVehicles.Add(value2.Key, value2);
			}
		}
		foreach (KeyValuePair<string, string> item in RPConfig.TimesOfDay)
		{
			if (!IsInvalid("time", item.Key, list))
			{
				mTimesOfDay.Add(item.Key, item.Value);
			}
		}
		foreach (KeyValuePair<string, string> item2 in RPConfig.Weather)
		{
			if (!IsInvalid("weather", item2.Key, list))
			{
				mWeather.Add(item2.Key, item2.Value);
			}
		}
	}

	private static bool IsInvalid(string type, string value, List<KeyValuePair<string, string>> invalid)
	{
		foreach (KeyValuePair<string, string> item in invalid)
		{
			if (item.Key == type && item.Value == value)
			{
				return true;
			}
		}
		return false;
	}
}
