using DoomDeathmatch.Component.MVC.Model.Weapon;

namespace DoomDeathmatch.Component.MVC.Model;

public class WeaponModel
{
  public event Action<WeaponData, WeaponData>? OnWeaponSelected;

  public IList<WeaponData> Weapons => _weapons;

  public WeaponData SelectedWeapon => _weapons[_selectedWeaponIndex];

  public int SelectedWeaponIndex
  {
    get => _selectedWeaponIndex;
    set
    {
      value = Math.Clamp(value, 0, _weapons.Count - 1);

      if (_selectedWeaponIndex == value)
        return;

      var oldSelectedWeapon = SelectedWeapon;
      _selectedWeaponIndex = value;
      OnWeaponSelected?.Invoke(oldSelectedWeapon, SelectedWeapon);
    }
  }

  private readonly List<WeaponData> _weapons = [WeaponData.Pistol];
  private int _selectedWeaponIndex = 0;
}