use std::sync::Arc;
use std::time::Duration;
use steamkit_protos::steam::{CAuthenticationAllowedConfirmation, EAuthSessionGuardType};
use tokio_util::sync::CancellationToken;
use crate::error::SteamError;
use crate::types::steam_id::SteamID;
use super::auth_poll_result::AuthPollResult;
use super::auth_session::AuthSession;
use super::i_authenticator::IAuthenticator;
pub struct CredentialsAuthSession {
session: AuthSession,
}
impl std::fmt::Debug for CredentialsAuthSession {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CredentialsAuthSession")
.field("session", &self.session)
.finish()
}
}
impl CredentialsAuthSession {
pub(crate) fn new(session: AuthSession) -> Self {
CredentialsAuthSession { session }
}
pub fn steam_id(&self) -> SteamID {
self.session.steam_id()
}
pub async fn send_steam_guard_code(
&self,
code: &str,
code_type: EAuthSessionGuardType,
) -> Result<(), SteamError> {
self.session.send_steam_guard_code(code, code_type).await?;
Ok(())
}
pub fn authenticator(&self) -> Option<&Arc<dyn IAuthenticator>> {
self.session.authenticator()
}
pub fn client_id(&self) -> u64 {
self.session.client_id()
}
pub fn request_id(&self) -> &[u8] {
self.session.request_id()
}
pub fn polling_interval(&self) -> Duration {
self.session.polling_interval()
}
pub fn allowed_confirmations(&self) -> &[CAuthenticationAllowedConfirmation] {
self.session.allowed_confirmations()
}
pub async fn polling_wait_for_result(
&self,
cancellation: CancellationToken,
) -> Result<AuthPollResult, SteamError> {
self.session.polling_wait_for_result(cancellation).await
}
pub async fn poll_auth_session_status(&self) -> Result<Option<AuthPollResult>, SteamError> {
self.session.poll_auth_session_status().await
}
}