namespace Engine.Graphics.Texture;

public class TextureUnitMap(int parCapacity)
{
  public int Size => _textures.Count;
  public int Capacity => parCapacity;
  public IReadOnlyDictionary<Texture, int> Textures => _textures;

  private readonly Dictionary<Texture, int> _textures = new();

  public int GetUnit(Texture parTexture)
  {
    if (_textures.TryGetValue(parTexture, out var unit))
    {
      return unit;
    }

    if (_textures.Count >= parCapacity)
    {
      throw new InvalidOperationException("Texture unit map is full");
    }

    unit = _textures.Count;
    _textures.Add(parTexture, unit);

    return unit;
  }

  public void Reset()
  {
    _textures.Clear();
  }
}