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

using LiteDB;

using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainService.Repositories;
using skydiveLogs_api.Infrastructure.Interfaces;


namespace skydiveLogs_api.Infrastructure
{
    public class JumpTypeRepository : IJumpTypeRepository
    {
        public JumpTypeRepository(IDataProvider dataProvider)
        {
            _dataProvider = dataProvider;
            _col = _dataProvider.CollOfJumpType;
        }

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

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

        public bool Update(JumpType updatedJumpType)
        {
            return _col.Update(updatedJumpType);
        }

        public bool Add(JumpType newJumpType)
        {
            var result = true;

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

            return result;
        }

        private readonly IDataProvider _dataProvider;

        private readonly ILiteCollection<JumpType> _col;
    }
}
