using Exam.Infrastructure.Data.Entity;
using Hotline.Exams.Base;
using System.Linq.Expressions;
using XF.Domain.Entities;
using XF.Domain.Repository;

namespace Hotline.Application.Exam.Extensions
{
    public static class RepositoryExtensions
    {
        public static bool CheckHasChild<TEntity>(this IRepository<TEntity> repository, EntityQueryRequest entityQueryRequest) where TEntity : class, IEntity<string>, IParentEntity, new()
        {
            if (entityQueryRequest.Id != null)
            {
                return repository.Queryable().Any(x=>x.ParentId == entityQueryRequest.Id);
            }
            else if(entityQueryRequest.Ids!=null && entityQueryRequest.Ids.Any())
            {
                return repository.Queryable().Any(x => entityQueryRequest.Ids.Contains(x.ParentId));
            }

            return false;
        }
    }
}
