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 IFinanceCollectionAccountService
    {
        Task Delete(Finance_Collection_Account account);
        Task<IEnumerable<Finance_Collection_Account>> GetList();
        Task<int> Save(Finance_Collection_Account account);
    }

    public class FinanceCollectionAccountService : IFinanceCollectionAccountService
    {
        IFinance_Collection_AccountRepository _accountRepository;

        public FinanceCollectionAccountService(IFinance_Collection_AccountRepository accountRepository)
        {
            _accountRepository = accountRepository;
        }

        public async Task<IEnumerable<Finance_Collection_Account>> GetList()
        {
            return await _accountRepository.QueryAsync();
        }

        public async Task<int> Save(Finance_Collection_Account account)
        {
            if (account.Id == 0)
                return (int)await _accountRepository.InsertAsync(account);
            else
            {
                var dbAccount = await _accountRepository.GetAsync(account.Id);
                await _accountRepository.UpdateAsync(account);
                return dbAccount.Id;
            }

        }

        public async Task Delete(Finance_Collection_Account account)
        {
            await _accountRepository.DeleteAsync(account);
        }


    }
}
