﻿using DataConnect.Data.MongoDb.BaseModule;
using DataConnect.Domain.PlanModule.Aggregates;
using DataConnect.Domain.PlanModule.Repositories;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace DataConnect.Data.MongoDb.PlanModule
{
    public class PlanRepository : BaseRepository<PlanWorkout>, IPlanRepository
    {
        protected IMongoCollection<PlanWorkout> CollectionPlanWorkout;
        public PlanRepository() : base(DbCollections.Activity)
        {
            CollectionPlanWorkout = Database.GetCollection<PlanWorkout>("PlanWorkout");
        }
        public async Task<List<PlanWorkout>> GetAsync(DateTime startDate, DateTime endDate)
        {
            var plans = await Collection.FindAsync(b => b.WorkoutDate >= startDate && b.WorkoutDate <= endDate);
            return plans.ToList();
        }

        public async Task UpdateAsync(PlanWorkout plan)
        {
            await Collection.DeleteOneAsync(b => b.WorkoutDate == plan.WorkoutDate);
            await Collection.InsertOneAsync(plan);
        }
    }
}
