using OpenTK.Mathematics;

namespace DoomDeathmatch.Component.MVC.Model.Weapon;

public class WeaponData
{
  public static WeaponData Pistol =>
    new(30)
    {
      Id = "pistol",
      Name = "Пистолет",
      Texture = "texture/pistol.png",
      Damage = 30,
      ShootPattern = new LineShootPattern()
    };

  public static WeaponData Shotgun =>
    new(10)
    {
      Id = "shotgun",
      Name = "Дробовик",
      Texture = "texture/shotgun.png",
      Damage = 5,
      ShootPattern = new RandomFlatSpreadShootPattern(MathHelper.DegreesToRadians(20), 40)
    };

  public string Id { get; private init; } = "";
  public string Name { get; private init; } = "";
  public string Texture { get; private init; } = "";
  public int Damage { get; private init; }
  public int MaxAmmo { get; }
  public IShootPattern ShootPattern { get; private init; }

  public int Ammo
  {
    get => _ammo;
    set
    {
      if (value < 0)
        value = 0;
      if (value > MaxAmmo)
        value = MaxAmmo;

      if (_ammo == value)
        return;

      _ammo = value;
      OnAmmoChanged?.Invoke(this);
    }
  }

  public event Action<WeaponData>? OnAmmoChanged;

  private int _ammo;

  private WeaponData(int parMaxAmmo)
  {
    MaxAmmo = parMaxAmmo;
    Ammo = MaxAmmo;
  }

  public override bool Equals(object? parObj)
  {
    return parObj is WeaponData weaponModel && Id == weaponModel.Id;
  }

  public override int GetHashCode()
  {
    return HashCode.Combine(Id);
  }
}