using System.Collections.Generic;
using System.Linq;

using LiteDB;

using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;


namespace skydiveLogs_api.Data
{
    public class GearRepository : IGearRepository
    {
        public GearRepository(IDataProvider dataProvider)
        {
            _dataProvider = dataProvider;
            _col = _dataProvider.CollOfGear;
        }

        public IEnumerable<Gear> GetAll()
        {
            return _col.FindAll().ToList();
        }

        public Gear GetById(int id)
        {
            return _col.FindById(new BsonValue(id));
        }

        public bool Update(Gear updatedGear)
        {
            return _col.Update(updatedGear);
        }

        public bool Add(Gear newGear)
        {
            var result = true;

            try
            {
                _col.Insert(newGear);
            }
            catch
            {
                result = false;
            }

            return result;
        }

        private readonly IDataProvider _dataProvider;

        private readonly ILiteCollection<Gear> _col;
    }
}
