using CoviDok.BLL;
using CoviDok.BLL.User.Managers;
using CoviDok.Data.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace CoviDok.Data.MySQL
{
    public class MySqlParentHandler : IParentHandler
    {
        private readonly MySqlContext context = new MySqlContext();
        public List<Child> GetChildren(int id)
        {
            return (from a in context.Children where a.DoctorId == id select a).ToList();
        }

        public async Task<Parent> GetParent(int id)
        {
            return await context.Parents.FindAsync(id);
        }

        public bool ParentExists(int id)
        {
            return context.Parents.Any(e => e.Id == id);
        }

        public async Task UpdateParent(int id, Parent value)
        {
            Parent Parent = await context.Parents.FindAsync(id);
            context.Entry(Parent).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            PropertyCopier<Parent>.Copy(value, Parent);
            await context.SaveChangesAsync();
        }
    }
}