using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Common.Standard;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Data.Model.Standard.Tracking;

namespace XYY.Service.Standard.TrackingService
{
    public interface ITraceSupplementConfigService
    {
        /// <summary>
        /// 添加配置
        /// </summary>
        /// <param name="supplementConfig"></param>
        /// <returns></returns>
        Task AddConfig(Logistics_Trace_SupplementConfig supplementConfig);

        /// <summary>
        /// 查找配置
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        Task<PageResult<Logistics_Trace_SupplementConfig>> QueryConfig(QueryModel queryModel);

        /// <summary>
        /// 获取所有配置
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        Task<List<Logistics_Trace_SupplementConfig>> GetAllConfig();

        /// <summary>
        /// 编辑配置
        /// </summary>
        /// <param name="supplementConfig"></param>
        /// <returns></returns>
        Task EditConfig(Logistics_Trace_SupplementConfig supplementConfig);

        /// <summary>
        /// 启用
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        Task Enable(int[] Ids);

        /// <summary>
        /// 禁用
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        Task Disable(int[] Ids);

        /// <summary>
        /// 移除
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        Task Delete(int[] Ids);

    }

    public class TraceSupplementConfigService : ITraceSupplementConfigService
    {
        private readonly IUnitOfWork _unitOfWork;

        public TraceSupplementConfigService(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        public async Task AddConfig(Logistics_Trace_SupplementConfig supplementConfig)
        {
            await _unitOfWork.InsertAsync(supplementConfig);
        }

        public async Task Delete(int[] Ids)
        {
            await _unitOfWork.UpdateByConditionAsync<Logistics_Trace_SupplementConfig, bool>(x => x.Id.In(Ids), new
            {
                IsDelete = true
            });
        }

        public async Task Disable(int[] Ids)
        {
            await _unitOfWork.UpdateByConditionAsync<Logistics_Trace_SupplementConfig, bool>(x => x.Id.In(Ids), new
            {
                IsEnable = false
            });
        }

        public async Task EditConfig(Logistics_Trace_SupplementConfig supplementConfig)
        {
            await _unitOfWork.UpdateAsync(supplementConfig);
        }

        public async Task Enable(int[] Ids)
        {
            await _unitOfWork.UpdateByConditionAsync<Logistics_Trace_SupplementConfig, bool>(x => x.Id.In(Ids), new
            {
                IsEnable = true
            });
        }

        public async Task<List<Logistics_Trace_SupplementConfig>> GetAllConfig()
        {
            return (await _unitOfWork.QueryAsync<Logistics_Trace_SupplementConfig>()).ToList();
        }

        public async Task<PageResult<Logistics_Trace_SupplementConfig>> QueryConfig(QueryModel queryModel)
        {
            return await _unitOfWork.GetPagingList2Async<Logistics_Trace_SupplementConfig>(queryModel);
        }
    }
}
