using Diligent.WebAPI.Business.Interfaces;
using Diligent.WebAPI.Data;
using Diligent.WebAPI.Data.Entities;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Business.Services
{
    public class RequestRepository : BaseRepository<Request>, IRequestRepository
    {
        protected new IMongoCollection<Request> _dbCollection;

        public RequestRepository(IMongoDBContext context) : base(context)
        {
            _dbCollection = _mongoContext.GetCollection<Request>(typeof(Request).Name);
        }

        public async Task<Request> FindRequestAsync(string customerId, string roomId)
        {
            var requests = await _dbCollection.FindAsync(x => x.SenderId == customerId && x.RoomId == roomId);
            return await requests.FirstOrDefaultAsync();
        }
    }
}
