using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Haoliang.Data.Repositories
{
    public interface IRepository<T> where T : class
    {
        Task<T> GetByIdAsync(int id);
        Task<IEnumerable<T>> GetAllAsync();
        Task<IEnumerable<T>> FindAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        Task<T> SingleOrDefaultAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        Task AddAsync(T entity);
        Task AddRangeAsync(IEnumerable<T> entities);
        void Update(T entity);
        void Remove(T entity);
        void RemoveRange(IEnumerable<T> entities);
        Task<int> CountAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate = null);
        Task<bool> ExistsAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        Task<int> SaveAsync();
    }

    public interface IReadRepository<T> where T : class
    {
        Task<T> GetByIdAsync(int id);
        Task<IEnumerable<T>> GetAllAsync();
        Task<IEnumerable<T>> FindAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        Task<T> SingleOrDefaultAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        Task<int> CountAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate = null);
        Task<bool> ExistsAsync(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
    }

    public interface IWriteRepository<T> where T : class
    {
        Task AddAsync(T entity);
        Task AddRangeAsync(IEnumerable<T> entities);
        void Update(T entity);
        void Remove(T entity);
        void RemoveRange(IEnumerable<T> entities);
        Task<int> SaveAsync();
    }
}