using System.Collections.Generic;
using Minesweeper.Config;
using Minesweeper.Core;

namespace Minesweeper.Presentation.ReadModels
{
    public sealed class GameReadModel : IGameReadModel
    {
        private readonly MinesweeperGameConfig config;
        private readonly IBoardService boardService;
        private readonly IGameStateService gameStateService;

        public GameReadModel(MinesweeperGameConfig config, IBoardService boardService, IGameStateService gameStateService)
        {
            this.config = config;
            this.boardService = boardService;
            this.gameStateService = gameStateService;
        }

        public GameState State => gameStateService.Current;
        public int Width => boardService.Width > 0 ? boardService.Width : config.Width;
        public int Height => boardService.Height > 0 ? boardService.Height : config.Height;
        public int MinesCount => boardService.MinesCount > 0 ? boardService.MinesCount : config.MinesCount;

        public bool TryGetCell(int x, int y, out BoardCellData cell)
        {
            return boardService.TryGetCell(x, y, out cell);
        }

        public IReadOnlyList<BoardCellData> GetCells()
        {
            return boardService.GetCells();
        }
    }
}
