using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Finance;
using Dapper;
using static XYY.Data.Standard.Finance.Finance_Customer_SupplementRepository;

namespace XYY.Data.Standard.Finance
{
    public interface IFinance_QutationApproveRepository : IBaseRepository<Finance_QutationApprove>
    {
        Task UpdateFeeOthersTo(List<Logistics_Fee_Other> others);
        Task BulkFeeOthers(List<Logistics_Fee_Other> others);
    }
    public class Finance_QutationApproveRepository : BaseRepository<Finance_QutationApprove>, IFinance_QutationApproveRepository
    {
        public Finance_QutationApproveRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }
        public async Task BulkFeeOthers(List<Logistics_Fee_Other> others)
        {
            await _unitOfWork.BulkToDBAsync(others);
        }
        public async Task UpdateFeeOthersTo(List<Logistics_Fee_Other> others)
        {
            if (others != null && others.Count > 0)
            {
                List<int> customerId = others.Select(x => x.CustomerId).Distinct().ToList();
                string sql = $" update  Logistics_Fee_Other set IsEffective=0 where FeeType={others[0].FeeType} and EffectiveDate='{others[0].EffectiveDate}' and CustomerId in ({string.Join(",", customerId)}) ";
                await _unitOfWork.ExecuteAsync(sql);
            }
        }
    }
}
