namespace Models.Game
{

    /// <summary>
    /// The Map class is the representation of the game map with the board and the operations table.
    /// </summary>
    public class Map
    {
        /// <summary>
        /// It is the list of cells on the map.
        /// </summary>
        public List<Cell> Boards { get; private set; }
        
        /// <summary>
        /// It is the backgrond image of the map
        /// </summary>
        public string Background { get; private set; }

        /// <summary>
        /// It is the grid of the possible operation in the game
        /// </summary>
        public List<OperationCell> OperationGrid { get; private set; }

        /// <summary>
        /// It is a list of a list containing user's rope paths in the current game
        /// </summary>
        public List<List<Cell>> RopePaths { get; private set; }

        /// <summary>
        /// It is a list of a list containing user's zones in the current game
        /// </summary>
        public List<List<Cell>> Zones { get; private set; }

        /// <summary>
        /// Initializes a new instance of the Map class.
        /// </summary>
        /// <param name="background">The background of the map.</param>
        public Map(string background)
        {
            Boards = InitializeBoards();
            Background = background;
            OperationGrid = InitializeOperationGrid();
            RopePaths = new List<List<Cell>>();
            Zones = new List<List<Cell>>();
        }

        /// <summary>
        /// Initializes the boards of the map.
        /// </summary>
        /// <returns>Return the boards</returns>
        private List<Cell> InitializeBoards()
        {
            var boards = new List<Cell>();
            for (int i = 0; i < 36; i++) // 6x6 board
            {
                boards.Add(new Cell(i / 6, i % 6));
            }
            return boards;
        }
        
        /// <summary>
        /// Initializes the operation grid of the map.
        /// </summary>
        /// <returns>Return the operation grid</returns>
        private List<OperationCell> InitializeOperationGrid()
        {
            var operationGrid = new List<OperationCell>();
            for (int i = 0; i < 5; i++) // 5 operations
            {
                for (int j = 0; j < 4; j++) // 4 cells per operation
                {
                    operationGrid.Add(new OperationCell(i, j));
                }
            }
            return operationGrid;
        }

        public bool CheckOperationPossible(int x)
        {
            return OperationGrid[x * 4 + 3].IsChecked;
        }
    }
}