using System.Collections.Generic;
using System.Linq;
using CommonClass.Factory;
using System;
using Cmdjy.Dal;

namespace Cmdjy.Bll.DataQuery
{
    /// <summary>
    /// 业务逻辑层数据查询接口
    /// </summary>
    public interface IDataQuery<T>
    {
        /// <summary>
        /// 查询配置
        /// </summary>
        DataQueryConfig Config { get; set; }
        /// <summary>
        /// 获取所有数据，可以从缓冲区获取
        /// </summary>
        /// <returns>数据枚举</returns>
        IEnumerable<T> GetAll();
        /// <summary>
        /// 通过Id获取数据。
        /// </summary>
        /// <param name="id">数据的Id</param>
        /// <returns>获取到的数据或Null</returns>
        T GetOneById(params object[] id);
        /// <summary>
        /// 获取数据查询。
        /// </summary>
        /// <param name="filter">查询筛选器</param>
        /// <returns>数据查询</returns>
        IQueryable<T> GetQuery(DjyDbContext db,DataFilterBase filter);
        /// <summary>
        /// 添加新数据
        /// </summary>
        /// <param name="one">要添加的数据</param>
        /// <returns>添加后的数据</returns>
        T AddNew(T one);
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="one">要删除的数据</param>
        /// <returns>删除后的数据</returns>
        T Remove(T one);
        /// <summary>
        /// 要更新的数据
        /// </summary>
        /// <param name="one">要更新的数据。</param>
        /// <returns>更新后的数据</returns>
        T Updata(T one);
    }
    /// <summary>
    /// 数据筛选器基类
    /// </summary>
    public class DataFilterBase
    {
    }
    /// <summary>
    /// 数据查询配置
    /// </summary>
    public class DataQueryConfig:IRegisterSelf
    {
        /// <summary>
        /// 是否允许使用缓冲
        /// </summary>
        public bool EnableCache { get; set; } = true;
        /// <summary>
        /// 缓冲过期时间
        /// </summary>
        public TimeSpan CacheTimeSpan { get; set; } = WebSettings.DefaultCacheTimeSpan;
    }
}
