using System.Collections.Generic;
using System.Linq;
using Demo.Models;

namespace Demo.Models
{
    public class BoardGameRepository
    {
          
          #region Fields

        private static readonly List<BoardGame> _Games = new List<BoardGame>()
        {
            new BoardGame
            {
                Id = 1,
                Name = "Chess",
                GameType = "Classic"
            },
            new BoardGame
            {
                Id = 2,
                Name = "Checkers",
                GameType = "Classic"
            },
            new BoardGame
            {
                Id = 3,
                Name = "Backgammon",
                GameType="Classic"
            },
            new BoardGame
            {
                Id = 4,
                Name = "Chutes and Ladders",
                GameType="Boardgame"
            },
            new BoardGame
            {
                Id = 5,
                Name = "Eagles Electric Football",
                GameType="Electric"
            }
        };

        #endregion

        public static BoardGame GetById(int id)
        {
            return _Games.First(g => g.Id == id);
        }

        public static IQueryable<BoardGame> GetGames()
        {
            return _Games.AsQueryable();
        }

        public static void Update(int id, BoardGame game)
        {
            var thisGame = _Games.First(g => g.Id == id);
            thisGame.Name = game.Name;
            thisGame.NumInStock = game.NumInStock;
            thisGame.GameType = game.GameType;
        }

        public static void Add(BoardGame game)
        {
            game.Id = _Games.Max(g => g.Id) + 1;
            _Games.Add(game);
        }

    }

}