using System;
using System.Text;

namespace TeslaConsole.BattleTech;

/// <summary>
/// A BattleTech combatant (mech pilot). Mirrors <c>RPPlayer</c> but carries the
/// BT-only participant fields (advanced damage model, pilot experience, mech
/// value, faction emblem, camo, patch colour and role). Free For All and No
/// Return use the same player type and differ only by the assigned
/// <see cref="Role" />.
/// </summary>
[Serializable]
internal class BTPlayer : BTParticipant
{
	private readonly string mName;

	private readonly string mVehicleKey;

	private readonly string mCamoKey;

	private readonly string mPatchKey;

	private readonly string mEmblemKey;

	private readonly string mExperienceKey;

	private readonly BTRole mRole;

	private readonly bool mAdvancedDamage;

	private readonly string mDropZoneKey;

	private readonly int mVehicleValue;

	public string Name => mName;

	public string VehicleKey => mVehicleKey;

	public string CamoKey => mCamoKey;

	public string PatchKey => mPatchKey;

	public string EmblemKey => mEmblemKey;

	public string ExperienceKey => mExperienceKey;

	public BTRole Role => mRole;

	public bool AdvancedDamage => mAdvancedDamage;

	public string DropZoneKey => mDropZoneKey;

	public int VehicleValue => mVehicleValue;

	public BTPlayer(string podHostAddress, string name, string vehicleKey, string camoKey, string patchKey, string emblemKey, string experienceKey, BTRole role, bool advancedDamage = true, string dropZoneKey = "one", int vehicleValue = 0)
		: base(podHostAddress, HostType.GameMachineHostType)
	{
		if (podHostAddress == null)
		{
			throw new ArgumentNullException("podHostAddress");
		}
		if (name == null)
		{
			throw new ArgumentNullException("name");
		}
		if (vehicleKey == null)
		{
			throw new ArgumentNullException("vehicleKey");
		}
		if (camoKey == null)
		{
			throw new ArgumentNullException("camoKey");
		}
		if (patchKey == null)
		{
			throw new ArgumentNullException("patchKey");
		}
		if (emblemKey == null)
		{
			throw new ArgumentNullException("emblemKey");
		}
		if (experienceKey == null)
		{
			throw new ArgumentNullException("experienceKey");
		}
		if (role == null)
		{
			throw new ArgumentNullException("role");
		}
		if (dropZoneKey == null)
		{
			throw new ArgumentNullException("dropZoneKey");
		}
		mName = name;
		mVehicleKey = vehicleKey;
		mCamoKey = camoKey;
		mPatchKey = patchKey;
		mEmblemKey = emblemKey;
		mExperienceKey = experienceKey;
		mRole = role;
		mAdvancedDamage = advancedDamage;
		mDropZoneKey = dropZoneKey;
		mVehicleValue = vehicleValue;
	}

	protected sealed override void AppendParticipantSpecificData(int index, StringBuilder sb)
	{
		sb.AppendFormat("advancedDamage={0}\n", mAdvancedDamage ? "1" : "0");
		sb.Append("loadzones=1\n");
		sb.AppendFormat("name={0}\n", mName);
		sb.AppendFormat("bitmapindex={0}\n", index);
		sb.AppendFormat("experience={0}\n", mExperienceKey);
		sb.AppendFormat("vehicle={0}\n", mVehicleKey);
		sb.AppendFormat("vehicleValue={0}\n", mVehicleValue);
		sb.AppendFormat("badge={0}\n", mEmblemKey);
		sb.AppendFormat("dropzone={0}\n", mDropZoneKey);
		sb.AppendFormat("color={0}\n", mCamoKey);
		sb.AppendFormat("patch={0}\n", mPatchKey);
		sb.AppendFormat("role=Role::{0}\n", mRole.Key);
	}
}
