using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace System.Common
{
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 获取数量
        /// </summary>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<int> GetCount(Expression<Func<T, bool>> whereExpression = null);
        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        Task<List<T>> GetList();
        Task<List<T>> GetListALL(Expression<Func<T, bool>> whereExpression);
        Task<List<T>> GetListALL(List<IConditionalModel> conModels, string orderby);
        Task<List<T>> GetListALL(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderExpression, OrderByType ordertype = OrderByType.Asc);

        /// <summary>
        /// 分页获取所有
        /// </summary>
        /// <returns></returns>
        Task<PageData<T>> GetListByPage(List<IConditionalModel> conModels, MyPageModel pagemodel);
        Task<PageData<T>> GetListByPage(List<IConditionalModel> conModels, MyPageModel pagemodel, string orderby);
        Task<PageData<T>> GetListByPage(Expression<Func<T, bool>> whereExpression, MyPageModel pagemodel);
        Task<PageData<T>> GetListByPage(Expression<Func<T, bool>> whereExpression, MyPageModel pagemodel, string orderby);

        Task<T> GetSingle(Expression<Func<T, bool>> whereExpression);
        Task<T> GetFirst(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> expression = null, OrderByType type = OrderByType.Asc);
        /// <summary>
        /// 添加
        /// </summary>
        Task<int> Add(T obj);
        /// <summary>
        /// 插入并返回实体
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        Task<T> AddAndUpdate(T obj,Expression<Func<T, object>> UpdateColumns= null);
        /// <summary>
        /// 插入并返回实体
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        Task<T> AddAndUpdateList(List<T> obj,Expression<Func<T, object>> UpdateColumns= null);
        /// <summary>
        /// 插入并返回影响行数
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        Task<bool> AddReturnCount(T obj);

        /// <summary>
        /// 添加排除某列
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        Task<int> AddIgnore(T obj, Expression<Func<T, object>> IgnoreColumns);


        /// <summary>
        /// 强势插入，插入自增值 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="isStrong">是否强势</param>
        /// <returns></returns>
        Task<int> AddStrong(T obj, bool isStrong = false);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="objlist"></param>
        /// <returns></returns>
        Task<bool> AddMany(List<T> objlist);

        /// <summary>
        /// 根据主键删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<bool> Delete(Expression<Func<T, bool>> whereExpression);

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<bool> Update(T obj);

        /// <summary>
        /// 条件更新
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<bool> Update(Expression<Func<T, T>> UpdateColumnsExpression, Expression<Func<T, bool>> whereExpression);


        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        Task<bool> UpdateList(List<T> obj);

        /// <summary>
        /// 批量指定字段更新
        /// </summary>
        /// <param name="objColumns">model => new { model.Name }</param>
        /// <returns></returns>
        Task<bool> UpdateListToColumns(List<T> obj, Expression<Func<T, object>> objColumns);


        Task<Data.DataTable> GetTableSugar(string sql, List<SugarParameter> sugarParameter = null);


        Task<int> ExecuteCommandSugar(string sql, List<SugarParameter> sugarParameter = null);

        Task<List<T>> GetModelSugar(string sql, List<SugarParameter> sugarParameter = null);

    }
}
