using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FrameworkDAL.DTO.SessionStore;
using GB5Shared.DTO.Framework.Login;
namespace FrameworkBLL.SessionStore
{
///
/// Orchestrates MSESSIONSTORE operations for the GB5 system database.
/// This is the session-management equivalent of BaseEntityAppService —
/// it is the single authoritative service for all login-session lifecycle events.
///
/// Callers (AuthenticationBLL) go through this BLL; they must never touch
/// ISessionStoreDAL directly.
///
public interface ISessionStoreBLL
{
///
/// Called on every successful login.
/// Inserts a new session row or refreshes LASTLOGINUSEDTIME if the session
/// already exists (safe upsert — handles re-login without duplicate-key errors).
/// Writes to the GB5 system database regardless of the tenant DB type.
///
Task InsertSessionAsync(SessionStoreDTO dto, LoginDTO login, CancellationToken ct = default);
///
/// Called on activity heartbeat to keep the session alive.
/// Updates LASTLOGINUSEDTIME. No-ops if the session no longer exists.
///
Task UpdateSessionAsync(int serverConfigId, int loginEventLogId, DateTime lastUsedTime, LoginDTO login, CancellationToken ct = default);
///
/// Called on explicit logout or forced logout.
/// Removes the session row from MSESSIONSTORE.
///
Task DeleteSessionAsync(int serverConfigId, int loginEventLogId, LoginDTO login, CancellationToken ct = default);
///
/// Called on explicit logout where the caller wants to know whether a session
/// actually existed (GB4 parity for User.svc's LogOutUser, which reports
/// "User Successfully LoggedOut." vs "User Not LoggedIn."). Checks for the
/// session first, deletes it if present, and reports which happened —
/// unlike , which is fire-and-forget.
///
Task LogOutIfPresentAsync(int serverConfigId, int loginEventLogId, LoginDTO login, CancellationToken ct = default);
///
/// Returns sessions that have been idle longer than .
/// Consumed by the auto-logout background job.
///
Task> GetUnusedSessionsAsync(int serverConfigId, int expiryMinutes, LoginDTO login, CancellationToken ct = default);
///
/// Housekeeping — removes session rows older than
/// and cleans up orphaned GB5ADMIN rows.
///
Task DeleteOldSessionsAsync(DateTime todayDate, LoginDTO login, CancellationToken ct = default);
}
}