
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 IdleFarmingApp : SqlSugarBaseApp<IdleFarming, SugarDbContext>
    {
        public IdleFarmingApp(
            ISugarUnitOfWork<SugarDbContext> unitWork,
            ISimpleClient<IdleFarming> repository,
            IAuth auth
            ) : base(unitWork, repository, auth)
        {

        }

        #region 查询
        /// <summary>
        /// 分页
        /// </summary>
        public async Task<Response<PageInfo<List<IdleFarming>>>> LoadPage(PageReq request)
        {
            RefAsync<int> totalCount = 0;
            var result = new PageInfo<IdleFarming>();
            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<IdleFarming>>>
            {
                Result = new PageInfo<List<IdleFarming>>
                {
                    Items = list,
                    Total = totalCount
                }
            };
        }

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

    }
}