using Dapper;
using Ewide.Core;
using Ewide.Core.Extension;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;

namespace Ewide.Application.Service
{
    [ApiDescriptionSettings(Name = "ServiceDoc")]
    public class Service : Interface, IDynamicApiController, ITransient
    {
        // Dapper仓储
        private readonly IDapperRepository _dapperRep;

        // 用户信息
        private readonly IUserManager _userManager;

        // 数据(实体Entity)仓储
        private readonly IRepository<Entity> _entityRep;

        public Service(
            IDapperRepository dapperRep,

            IUserManager userManager,

            IRepository<Entity> entityRep
        )
        {
            _dapperRep = dapperRep;

            _userManager = userManager;

            _entityRep = entityRep;
        }

        /// <summary>
        /// 查询 - EF方式
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<dynamic> Page(DtoPageInput input)
        {
            var data = await _entityRep.DetachedEntities.ToPageData(input);
            return PageDataResult<Entity>.PageResult(data);
        }

        /// <summary>
        /// 查询 - Dapper方式
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<dynamic> Page(DtoPageInput input)
        {
            var sql = "...";
            var data = await _dapperRep.QueryPageDataDynamic(sql, input);
            return data;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Add(DtoAddInput input)
        {

        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Update(DtoUpdateInput input)
        {

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Delete(DtoDeleteInput input)
        {

        }
    }
}