using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Data.Standard.Finance;
using XYY.Model.Standard.Finance; 

namespace XYY.Service.Standard.Finance
{
    public interface IRateService
    {
        Task AddRate(Finance_Rate rate);
        Task EditRate(Finance_Rate rate);
        Task<List<Finance_Rate>> GetRates();
    }

    public class RateService : IRateService
    {
        IFinance_RateRepository _rateRepository;
        public RateService(IFinance_RateRepository rateRepository)
        {
            _rateRepository = rateRepository;
        }

        public async Task AddRate(Finance_Rate rate)
        {
            await _rateRepository.InsertAsync(rate);
        }

        public async Task EditRate(Finance_Rate rate)
        {
            await _rateRepository.UpdateAsync(rate);
        }

        public async Task<List<Finance_Rate>> GetRates()
        {
            return (await _rateRepository.QueryAsync()).OrderByDescending(x => x.Currency).OrderByDescending(x => x.StartDate).OrderByDescending(x => x.EndDate).ToList();
        }
    }
}
