#nullable enable
using AdvChkSys.Chunk;

namespace AdvChkSys.Spatial
{
    /// <summary>
    /// Provides extension methods for chunks to work with spatial indexing.
    /// </summary>
    public static class ChunkExtensions
    {
        /// <summary>
        /// Converts a Chunk3D to an IChunk3D.
        /// </summary>
        public static IChunk3D AsIChunk3D<T>(this Chunk3D<T> chunk)
        {
            return new Chunk3DAdapter<T>(chunk);
        }

        /// <summary>
        /// Adapter to make Chunk3D implement IChunk3D.
        /// </summary>
        private class Chunk3DAdapter<T> : IChunk3D
        {
            private readonly Chunk3D<T> _chunk;

            public Chunk3DAdapter(Chunk3D<T> chunk)
            {
                _chunk = chunk;
            }

            public int X => _chunk.X;
            public int Y => _chunk.Y;
            public int Z => _chunk.Z;
            public int Width => _chunk.Width;
            public int Height => _chunk.Height;
            public int Depth => _chunk.Depth;
            public System.Collections.Generic.Dictionary<string, object> Metadata => _chunk.Metadata;
        }
    }
}