using System;
using System.Xml;

namespace TeslaConsole.BattleTech;

/// <summary>
/// A BattleTech pilot role. Each participant references one role
/// (<c>role=Role::&lt;Key&gt;</c>); the egg then carries a matching
/// <c>[Role::&lt;Key&gt;] model=&lt;Model&gt;</c> block. Free For All uses the
/// Default role, No Return uses the NoReturn role. Serializable because it is
/// reachable from a saved <see cref="BTMissionResults" /> via the mission's
/// players (mirrors the .rpm save mechanism).
/// </summary>
[Serializable]
public class BTRole
{
	private readonly string mKey;

	private readonly string mModel;

	private readonly string mName;

	public string Key => mKey;

	public string Model => mModel;

	public string Name => mName;

	internal BTRole(XmlNode roleNode)
	{
		mKey = roleNode.Attributes["key"].InnerText;
		mModel = roleNode.Attributes["model"].InnerText;
		XmlAttribute xmlAttribute = roleNode.Attributes["name"];
		mName = ((xmlAttribute != null) ? xmlAttribute.InnerText : mKey);
	}

	public BTRole(string key, string model, string name)
	{
		mKey = key;
		mModel = model;
		mName = name;
	}

	public override string ToString()
	{
		return mName;
	}
}
