
using OpenAuth.App.Interface;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using Infrastructure;
using OpenAuth.App.Request;
using OpenAuth.Repository;
using SqlSugar;

namespace OpenAuth.App
{
    public class IdleWatersApp : SqlSugarBaseApp<IdleWaters, SugarDbContext>
    {
        public IdleWatersApp(
            ISugarUnitOfWork<SugarDbContext> unitWork,
            ISimpleClient<IdleWaters> repository,
            IAuth auth
            ) : base(unitWork, repository, auth)
        {

        }

        #region 查询
        /// <summary>
        /// 分页
        /// </summary>
        public async Task<Response<PageInfo<List<IdleWaters>>>> LoadPage(PageReq request)
        {         
            RefAsync<int> totalCount = 0;
            var result = new PageInfo<IdleWaters>();
            var list = await base.Repository.AsQueryable()
                .WhereIF(!string.IsNullOrEmpty(request.key), a => a.SerialNumber.Contains(request.key))
                .ToPageListAsync(request.page, request.limit, totalCount);

            return new Response<PageInfo<List<IdleWaters>>>
            {
                Result = new PageInfo<List<IdleWaters>>
                {
                    Items = list,
                    Total = totalCount
                }
            };
        }


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IdleWaters> Detail(string id)
        {
            return await Repository.GetByIdAsync(id);
        }
        #endregion
    }
}