using Demo.Data.LocalData;
using Demo.Data.RemoteData.RemoteDataBase;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Demo.Data.Repository
{
    public class PresenceRepositoryImpl : IPresenceRepository
    {
        private List<PresenceLocalEntity> _presences;

        public PresenceRepositoryImpl()
        {
            _presences = new List<PresenceLocalEntity>(); // Ваши реальные данные
        }

        public void SavePresence(List<PresenceLocalEntity> presences)
        {
            foreach (var presence in presences)
            {
                var existingPresence = _presences.FirstOrDefault(p =>
                    p.Date == presence.Date &&
                    p.UserId == presence.UserId &&
                    p.LessonNumber == presence.LessonNumber);

                if (existingPresence == null)
                {
                    _presences.Add(presence);
                }
                else
                {
                    existingPresence.IsAttedance = presence.IsAttedance;
                }
            }
        }

        public List<PresenceLocalEntity> GetPresenceByDateAndGroup(DateTime date, int groupId)
        {
            return _presences.Where(p => p.Date.Date == date.Date &&
                                         LocalStaticData.users.Any(u => u.GroupID == groupId && u.ID == p.UserId)).ToList();
        }

        public List<PresenceLocalEntity> GetPresenceByGroup(int groupId)
        {
            return _presences.Where(p => p.GroupId == groupId).ToList();
        }

        public List<PresenceDao> GetPresenceByDateAndGroupDao(DateTime date, int groupId)
        {
            throw new NotImplementedException();
        }

        public void SavePresenceDao(List<PresenceDao> presences)
        {
            throw new NotImplementedException();
        }

        public List<PresenceDao> GetPresenceByGroupDao(int groupId)
        {
            throw new NotImplementedException();
        }
    }
}
