namespace Health.Application.Notifications;

public sealed record InAppNotificationDto(
    Guid Id,
    string Type,
    string Title,
    string Message,
    string Severity,
    string? ActionType,
    string? ActionTargetId,
    bool IsRead,
    DateTime CreatedAt);

public sealed record NotificationMessage(
    string Type,
    string Title,
    string Message,
    string Severity,
    string? ActionType,
    string? ActionTargetId);

public interface IInAppNotificationService
{
    Task<IReadOnlyList<InAppNotificationDto>> GetPendingAsync(Guid userId, CancellationToken ct);
    Task<IReadOnlyList<InAppNotificationDto>> GetHistoryAsync(Guid userId, CancellationToken ct);
    Task<bool> AcknowledgeAsync(Guid userId, Guid notificationId, CancellationToken ct);
    Task<int> MarkAllReadAsync(Guid userId, CancellationToken ct);
    Task<bool> DeleteAsync(Guid userId, Guid notificationId, CancellationToken ct);
}

public interface IInAppNotificationRepository
{
    Task<IReadOnlyList<InAppNotificationRecord>> GetPendingAsync(Guid userId, CancellationToken ct);
    Task<IReadOnlyList<InAppNotificationRecord>> GetHistoryAsync(Guid userId, CancellationToken ct);
    Task<bool> AcknowledgeAsync(Guid userId, Guid notificationId, CancellationToken ct);
    Task<int> MarkAllReadAsync(Guid userId, CancellationToken ct);
    Task<bool> DeleteAsync(Guid userId, Guid notificationId, CancellationToken ct);
}

public sealed record InAppNotificationRecord(
    Guid Id,
    string Type,
    string Title,
    string Message,
    string Severity,
    string? ActionType,
    string? ActionTargetId,
    bool IsRead,
    DateTime CreatedAt);

public interface IUserNotificationProducer
{
    Task<bool> EnqueueAsync(Guid userId, Guid sourceId, NotificationMessage message, CancellationToken ct);
}

public interface INotificationOutboxProcessor
{
    Task RecoverStaleAsync(CancellationToken ct);
    Task<bool> ProcessNextAsync(CancellationToken ct);
}
