using System.Linq.Expressions;

namespace QYZH.InteractiveMagazine.IService;

/// <summary>
/// 基础服务定义
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IBaseService<T> where T : class, new()
{
    Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);

    /// <summary>
    /// 根据条件表达式查询单条数据
    /// </summary>
    /// <param name="expression">表达式</param>
    /// <returns>泛型实体</returns>
    Task<R> GetByIdAsync<R>(Expression<Func<T, bool>> expression) where R : class;

    Task<R> GetByExpressionAsync<R>(Expression<Func<T, bool>> expression) where R : class;

    Task<List<T2>> GetListByExpression<T2>(Expression<Func<T, bool>> expression) where T2 : class;

    Task<bool> UpdateAsync(T updateObj);

    ///// <summary>
    ///// 根据指定条件更新指定列 eg：Update(new SysUser(){ Status = 1 }, it => new { it.Status }, f => f.Userid == 1));
    ///// 只更新Status列，条件是包含
    ///// </summary>
    ///// <param name="entity">实体类</param>
    ///// <param name="expression">要更新列的表达式</param>
    ///// <param name="where">where表达式</param>
    ///// <returns></returns>
    //Task<bool> UpdateAsync(T entity, Expression<Func<T, object>> expression, Expression<Func<T, bool>> where);

    Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);

    Task<bool> UpdateAsync(Expression<Func<T, bool>> columns, Expression<Func<T, bool>> where);
}
