gehgassi_backend/gehGassi.Core/Interfaces/IPushNotificationService.cs

396 lines
16 KiB
C#

using gehGassi.Domain.Pushnotifications;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using gehGassi.Domain.Common;
using System.Text.Json;
namespace gehGassi.Core.Interfaces
{
/// <summary>
/// Schnittstellenbeschreibung für einen Service der Push-Notifications senden kann
/// </summary>
public interface IPushNotificationService
{
/// <summary>
/// Registrieren eines Gerätes für Pushnotifications
/// </summary>
/// <param name="deviceInstallation">Informationen für die Installation / Registrierung</param>
/// <returns>True wenn erfolgreich, false sonst</returns>
Task<bool> CreateOrUpdateInstallationAsync(DeviceInstallation deviceInstallation);
/// <summary>
/// Löschen der Registrierung eines Gerätes für Pushnotifications
/// </summary>
/// <param name="installationId">Id der Installation</param>
/// <returns></returns>
Task<bool> DeleteInstallationByIdAsync(string installationId);
/// <summary>
/// Senden einer Pushnotification Nachricht
/// </summary>
/// <param name="notificationMessage">Nachricht die gesendet werden soll</param>
/// <returns>true wenn gesendet, false sonst</returns>
Task<bool> SendNotificationAsync(NotificationMessage notificationMessage);
/// <summary>
/// Senden einer Pushnotification Nachricht
/// </summary>
/// <param name="notificationMessage">Nachricht die gesendet werden soll</param>
/// <param name="tags">Liste zusätzlicher Tags für die Adressierung der Ziele</param>
/// <returns>true wenn gesendet, false sonst</returns>
Task<bool> SendNotificationAsync(NotificationMessage notificationMessage, List<string> tags);
/// <summary>
/// Auflisten der registrierten Geräte
/// </summary>
/// <returns>Task</returns>
Task ListRegistrationsAsync();
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine neue Nachricht für ihn eingetroffen ist
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="conversationId">Id des Konversation</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendNewMessageAsync(string receiverId, string conversationId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine neue Text-Nachricht von gehgassi für ihn eingetroffen ist
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="messageId">Id der Nachricht</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendNewTextMessageAsync(string receiverId, string messageId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein neuer Walk für ihn eingetroffen ist
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendNewWalkAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn sich eine öffentliche Anfrage geändert hat
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkRequestChangedAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn sich eine öffentliche Anfrage in der Nähe verfügbar ist
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkRequestAvailableAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine Antwort auf eine öffentliche Anfrage erstellt wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkResponseAddedAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine Antwort auf eine öffentliche Anfrage sich geändert hat
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkResponseChangedAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine Antwort auf eine öffentliche Anfrage stonriert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkResponseCancelledAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine Antwort auf eine öffentliche Anfrage abgelehnt wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkResponseDeclinedAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn eine öffentliche anfrage storniert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="publicWalkRequestId">Id des öffentlichen Anfrage</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPublicWalkRequestCancelledAsync(string receiverId, string publicWalkRequestId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk storniert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <param name="appMode">App-Mode</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkCancelledAsync(string receiverId, string walkId, AppMode appMode);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk gestartet wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkStartedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk abgeschlossen wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkCompletedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk abgeschlossen wurde als Erinnerung
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkCompletedReminderAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk angenommen wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkAcceptedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk abgelehnt wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkDeclinedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk angefragt wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkRequestedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk bestätigt wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkConfirmedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk reklamiert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkComplainedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Walk reklamiert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <param name="appMode">App-Mode</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkComplainedUpdateAsync(string receiverId, string walkId, AppMode appMode);
/// <summary>
/// Sendet eine Pushnotification an einen Hundebesitzer wenn die Bezahlung für einen ein Walk gescheitert ist.
/// Wird verwendet wenn das Payment nicht funktioniert hat und der Hundebesitzer den Walk neu buchen muss.
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="walkId">Id des Walks</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendWalkPaymentFailedAsync(string receiverId, string walkId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein KYC-Status (Dokument) geändert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="documentId">Id des KYC-Dokuments</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendIdentityDocumentUpdateAsync(string receiverId, string documentId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User wenn ein Auszahlungsstatus geändert wurde
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <param name="payoutId">Id der Auszahlung</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendPayoutUpdateAsync(string receiverId, string payoutId);
/// <summary>
/// Sendet eine Pushnotification an einen App-User dass ein Logout durchgeführt werden soll
/// </summary>
/// <param name="receiverId">ID des App-Users</param>
/// <returns>true wenn erfolgreich, false sonst</returns>
Task<bool> SendLogoutAsync(string receiverId);
}
/// <summary>
/// Hilfsklasse zum abspeichern der referenz-Info für Server PushNotifications
/// </summary>
public class ServerPushNotificationInfo
{
/// <summary>
/// Title der Nachricht
/// </summary>
[JsonPropertyName("title")]
public string Title { get; set; }
/// <summary>
/// Inhalt der Nachricht
/// </summary>
[JsonPropertyName("body")]
public string Body { get; set; }
/// <summary>
/// Daten der Nachricht
/// </summary>
[JsonPropertyName("data")]
public string Data { get; set; }
/// <summary>
/// Typ des Appusers damit man bei jenen die beides sind auch unterscheiden kann
/// </summary>
[JsonPropertyName("appMode")]
[JsonConverter(typeof(AppModeConverter))]
public AppMode? AppMode { get; set; }
/// <summary>
/// Id des verknüpften Objektes
/// </summary>
[JsonPropertyName("key")]
public string Key { get; set; }
/// <summary>
/// Typ des Objektes das verbunden wurde
/// </summary>
[JsonPropertyName("table")]
public string Table { get; set; }
/// <summary>
/// Typ der Systemnachricht
/// </summary>
[JsonPropertyName("type")]
[JsonConverter(typeof(SystemMessageTypeConverter))]
public SystemMessageType? Type { get; set; }
/// <summary>
/// Id der Nachricht für Cancel
/// </summary>
[JsonPropertyName("notificationId")]
public int NotificationId { get; set; }
}
public class SystemMessageTypeConverter : JsonConverter<SystemMessageType?>
{
public override SystemMessageType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
try
{
var value = reader.GetInt32();
return (SystemMessageType)value;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
try
{
var stringVal = reader.GetString();
if (string.IsNullOrEmpty(stringVal))
{
return null;
}
var intVal = int.Parse(stringVal);
return (SystemMessageType)intVal;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
return null;
}
public override void Write(Utf8JsonWriter writer, SystemMessageType? value, JsonSerializerOptions options)
{
if (value == null)
{
writer.WriteNullValue();
return;
}
var intVal = (int)value;
writer.WriteNumberValue(intVal);
}
}
public class AppModeConverter : JsonConverter<AppMode?>
{
public override AppMode? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
try
{
var value = reader.GetInt32();
return (AppMode)value;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
try
{
var stringVal = reader.GetString();
if (string.IsNullOrEmpty(stringVal))
{
return null;
}
var intVal = int.Parse(stringVal);
return (AppMode)intVal;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
return null;
}
public override void Write(Utf8JsonWriter writer, AppMode? value, JsonSerializerOptions options)
{
if (value == null)
{
writer.WriteNullValue();
return;
}
var intVal = (int)value;
writer.WriteNumberValue(intVal);
}
}
}