using System;
using Svrnty.CQRS.Events.Abstractions.Subscriptions;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Svrnty.CQRS.Events.Abstractions.Models;
namespace Svrnty.CQRS.Events.Abstractions.Subscriptions;
///
/// Service for managing event subscriptions.
/// Provides high-level operations for subscribing, unsubscribing, and managing subscriptions.
///
public interface IEventSubscriptionService
{
///
/// Create a new subscription to events for a correlation ID.
///
/// Subscription request details.
/// Cancellation token.
/// The created subscription.
Task SubscribeAsync(SubscriptionRequest request, CancellationToken cancellationToken = default);
///
/// Unsubscribe from events (marks subscription as cancelled).
///
/// The subscription ID to cancel.
/// Cancellation token.
Task UnsubscribeAsync(string subscriptionId, CancellationToken cancellationToken = default);
///
/// Get all active subscriptions for a subscriber (for catch-up on reconnect).
///
/// The subscriber ID.
/// Cancellation token.
/// List of active subscriptions.
Task> GetActiveSubscriptionsAsync(string subscriberId, CancellationToken cancellationToken = default);
///
/// Mark a subscription as completed (terminal event received).
///
/// The subscription ID.
/// Cancellation token.
Task CompleteSubscriptionAsync(string subscriptionId, CancellationToken cancellationToken = default);
///
/// Update the last delivered sequence for a subscription.
///
/// The subscription ID.
/// The sequence number that was delivered.
/// Cancellation token.
Task UpdateLastDeliveredAsync(string subscriptionId, long sequence, CancellationToken cancellationToken = default);
}
///
/// Request to create a new event subscription.
///
public sealed class SubscriptionRequest
{
///
/// ID of the subscriber (typically user ID or client ID).
///
public required string SubscriberId { get; init; }
///
/// Correlation ID to subscribe to.
///
public required string CorrelationId { get; init; }
///
/// Event types to receive (empty = all types).
///
public HashSet EventTypes { get; init; } = new();
///
/// Event types that complete the subscription.
///
public HashSet TerminalEventTypes { get; init; } = new();
///
/// How events should be delivered.
///
public DeliveryMode DeliveryMode { get; init; } = DeliveryMode.Immediate;
///
/// Optional timeout duration for this subscription.
///
public TimeSpan? Timeout { get; init; }
}