using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using Voile.Extensions;

namespace Voile;

public class GridSet<T>
{
    /// <summary>
    /// The size of a cell of this <see cref="GridSet"/>.
    /// </summary>
    public float CellSize { get; }
    public GridSet(float cellSize = 32.0f)
    {
        CellSize = cellSize;
    }

    /// <summary>
    /// Add an element to this <see cref="GridSet"/>.
    /// </summary>
    /// <param name="position">Position of the element in this <see cref="GridSet"/>.</param>
    /// <param name="child">Element to add.</param>
    public void Add(Vector2 position, T child)
    {
        var snap = Vector2.One * CellSize;
        position = position.Snapped(snap);

        if (_values.TryGetValue(position, out var list))
        {
            list.Add(child);
        }
        else
        {
            _values.Add(position, new List<T>());
        }
    }

    /// <summary>
    /// Removes an element from this <see cref="GridSet"/>.
    /// </summary>
    /// <param name="child">Element to remove.</param>
    public void Remove(T child) => throw new NotImplementedException();

    private Dictionary<Vector2, List<T>> _values = new();
}