using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using gehGassi.Core.Interfaces; using gehGassi.Domain.Common; using gehGassi.Domain.Favourites; using gehGassi.Domain.Payment; using Microsoft.EntityFrameworkCore; namespace gehGassi.Core.Services { /// /// Service der die Verwaltung von KYC-Dokumenten ermöglicht /// public class IdentityDocumentService : ServiceBase, IIdentityDocumentService { /// /// Erstellt eine Instanz /// /// Instanz eines IUnitOfWork public IdentityDocumentService(IUnitOfWork unitOfWork) : base(unitOfWork) { } /// /// Erstellen eines KYC-Dokuments /// /// IdentityDocument public IdentityDocument Create() { var item = new IdentityDocument() { Id = Guid.NewGuid().ToString("N"), Created = DateTimeOffset.UtcNow }; return item; } /// /// Erstellen eines KYC-Dokuments /// /// Id des App-Users /// Id des KYC-Dokumentes bei MangoPay /// Id des Users bei MangoPay /// Typ des Dokumentes /// Quelle / Dokumentenart /// Status der Validierung des Dokumentes /// Anzahl der Seiten /// IdentityDocument public IdentityDocument Create(string appUserId, string mangoPayId, string mangoPayUserId, IdentityDocumentType documentType, IdentityDocumentSource source, IdentityDocumentStatus status, int pageCount) { var item = Create(); item.AppUserId = appUserId; item.MangoPayId = mangoPayId; item.MangoPayUserId = mangoPayUserId; item.Type = documentType; item.Source = source; item.Status = status; item.PageCount = pageCount; return item; } /// /// Gibt ein KYC-Dokument anhand der MangoPayId zurück /// /// Id des Dokumentes bei MangoPay /// IdentityDocument oder null, wenn nicht gefunden public async Task GetByMangoPayIdAsync(string mangoPayId) { var item = await Repository.FirstOrDefaultAsync(c => c.MangoPayId == mangoPayId).ConfigureAwait(false); return item; } /// /// Gibt ein KYC-Dokument zurück, bei welchem die Validierung noch läuft /// /// Id des App-USers /// IdentityDocument oder null, wenn keines gefunden public async Task GetValidationInProgressAsync(string appUserId) { var item = await Repository.FirstOrDefaultAsync(c => c.AppUserId == appUserId && c.Status == IdentityDocumentStatus.VALIDATION_ASKED).ConfigureAwait(false); return item; } /// /// Gibt das zuletzt erstellte KYC-Dokument für einen App-User zurück /// /// Id des App-USers /// IdentityDocument oder null, wenn keines gefunden public async Task GetLatestAsync(string appUserId) { var item = await Repository.Query(c => c.AppUserId == appUserId).OrderByDescending(c => c.Created).FirstOrDefaultAsync().ConfigureAwait(false); return item; } } }