using OpenAuth.App.Base;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
using OpenAuth.App.Interface;
using Infrastructure;
using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Request;

namespace OpenAuth.App
{
    public class WFSchemeApp : SqlSugarBaseApp<WFScheme, SugarDbContext>
    {
        ISqlSugarClient client;
        public WFSchemeApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<WFScheme> repository, IAuth auth) : base(unitWork, repository, auth)
        {
            client = base.Repository.AsSugarClient();
        }

       

        public async Task<PageInfo<List<WFScheme>>> GetSchemePageList(PageReq pageReq, string schemeInfoId)
        {
            RefAsync<int> totalCount = 0;

            var list = await client.Queryable<WFScheme>()
                .Where(a => a.SchemeInfoId == schemeInfoId)
                .OrderByDescending(a => a.CreateDate)
                .ToPageListAsync(pageReq.page, pageReq.limit, totalCount);

            return new PageInfo<List<WFScheme>>
            {
                Items = list,
                Total = totalCount
            };
        }


        /// <summary>
        /// 获取模板列表
        /// </summary>
        /// <param name="schemeInfoId">流程信息主键</param>
        /// <returns></returns>
        public async Task<List<WFScheme>> GetSchemeList(string schemeInfoId)
        {
            return await client.Queryable<WFScheme>()
                .Where(t => t.SchemeInfoId == schemeInfoId)
                .OrderByDescending(t => t.CreateDate)
                .ToListAsync();
        }
    }
}
