using System;

namespace AdvChkSys.Constraints
{
    /// <summary>
    /// Represents constraints and limits for the chunk world.
    /// Can be used to restrict world size, chunk counts, and other resource limits.
    /// </summary>
    public class WorldConstraints
    {
        /// <summary>
        /// If set, the minimum allowed chunk X coordinate (inclusive).
        /// </summary>
        public int? MinChunkX { get; set; }

        /// <summary>
        /// If set, the maximum allowed chunk X coordinate (inclusive).
        /// </summary>
        public int? MaxChunkX { get; set; }

        /// <summary>
        /// If set, the minimum allowed chunk Y coordinate (inclusive).
        /// </summary>
        public int? MinChunkY { get; set; }

        /// <summary>
        /// If set, the maximum allowed chunk Y coordinate (inclusive).
        /// </summary>
        public int? MaxChunkY { get; set; }

        /// <summary>
        /// If set, the minimum allowed chunk Z coordinate (inclusive).
        /// </summary>
        public int? MinChunkZ { get; set; }

        /// <summary>
        /// If set, the maximum allowed chunk Z coordinate (inclusive).
        /// </summary>
        public int? MaxChunkZ { get; set; }

        /// <summary>
        /// If set, the maximum number of chunks allowed to be loaded in memory at once.
        /// </summary>
        public int? MaxLoadedChunks { get; set; }

        /// <summary>
        /// Checks if the given chunk coordinates are within the allowed world bounds.
        /// </summary>
        public bool IsWithinBounds(int chunkX, int chunkY)
        {
            if (MinChunkX.HasValue && chunkX < MinChunkX.Value) return false;
            if (MaxChunkX.HasValue && chunkX > MaxChunkX.Value) return false;
            if (MinChunkY.HasValue && chunkY < MinChunkY.Value) return false;
            if (MaxChunkY.HasValue && chunkY > MaxChunkY.Value) return false;
            return true;
        }

        /// <summary>
        /// Checks if the current number of loaded chunks is within the allowed limit.
        /// </summary>
        public bool IsWithinChunkLimit(int loadedChunkCount)
        {
            if (MaxLoadedChunks.HasValue && loadedChunkCount > MaxLoadedChunks.Value) return false;
            return true;
        }
    }
}