using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using gehGassi.Core.Interfaces;
using gehGassi.Domain.Common;
using gehGassi.Domain.Payment;
namespace gehGassi.Core.Services
{
///
/// Service der die Verwaltung von Wallets ermöglicht
///
public class WalletService : ServiceBase, IWalletService
{
///
/// Erstellt eine Instanz
///
/// Instanz eines IUnitOfWork
public WalletService(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
///
/// Erstellen eines Wallets für einen AppUser
///
/// Id des AppUsers
/// ID des Walltes bei Mangopay
/// Typ des Wallets
/// Id des Payment Owners (PaymentId)
/// Währung ISO 4217 Code
/// Beschreibung
/// Wallet
public Wallet Create(string appUserId, string walletId, WalletType type, string ownerId, string currency, string description)
{
var wallet = new Wallet
{
Id = Guid.NewGuid().ToString("N"),
AppUserId = appUserId,
Type = type,
OwnerId = ownerId,
WalletId = walletId,
Currency = currency,
Description = description,
Balance = 0,
UpdatedAt = DateTimeOffset.UtcNow
};
return wallet;
}
///
/// Gibt ein Wallet für einen AppUser mit einem Typ zurück
///
/// Id des AppUsers
/// Typ des Wallets
/// Wallet oder null, wenn nicht gefunden
public async Task GetAsync(string appUserId, WalletType type)
{
var wallet = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.Type == type).ConfigureAwait(false);
return wallet;
}
///
/// Gibt eine Liste aller Wallets eines AppUsers zurück
///
/// Id des AppUsers
/// Liste von Wallets
public async Task> GetAllAsync(string appUserId)
{
return (await Repository.FindAsync(c => c.AppUserId == appUserId).ConfigureAwait(false)).ToList();
}
}
}