#nullable enable
using Baya.Domain.Entities.User;

namespace Baya.Application.Contracts.Persistence;

public interface IUserSessionRepository
{
    Task AddAsync(UserSession session, CancellationToken cancellationToken);

    /// <summary>Tracked lookup by refresh-token hash (with the owning user), regardless of revocation —
    /// the refresh flow needs to see revoked sessions to detect stolen-token reuse.</summary>
    Task<UserSession?> GetByTokenHashAsync(string refreshTokenHash, CancellationToken cancellationToken);

    /// <summary>Tracked lookup of a caller-owned, still-active session (single-device logout).</summary>
    Task<UserSession?> GetActiveForUserByTokenHashAsync(int userId, string refreshTokenHash, CancellationToken cancellationToken);

    /// <summary>Marks every active session of the user revoked (logout-everywhere / reuse detection).
    /// Changes are persisted by the caller's commit.</summary>
    Task<int> RevokeAllActiveForUserAsync(int userId, DateTimeOffset revokedAt, CancellationToken cancellationToken);
}