use async_trait::async_trait;
use wami_core::error::Result;
use crate::wami::oauth::{AccessToken, AuthorizationCode, OAuthClient, RefreshToken, UserConsent};
#[async_trait]
pub trait OAuthClientStore: Send + Sync {
async fn create_oauth_client(&mut self, client: OAuthClient) -> Result<OAuthClient>;
async fn get_oauth_client(&self, client_id: &str) -> Result<Option<OAuthClient>>;
async fn update_oauth_client(&mut self, client: OAuthClient) -> Result<OAuthClient>;
async fn delete_oauth_client(&mut self, client_id: &str) -> Result<()>;
async fn list_oauth_clients(&self) -> Result<Vec<OAuthClient>>;
}
#[async_trait]
pub trait OAuthTokenStore: Send + Sync {
async fn record_oauth_token(&mut self, token: AccessToken) -> Result<AccessToken>;
async fn get_oauth_token(&self, jti: &str) -> Result<Option<AccessToken>>;
async fn revoke_oauth_token(&mut self, jti: &str) -> Result<bool>;
async fn revoke_oauth_tokens_for_client(&mut self, client_id: &str) -> Result<u64>;
async fn list_oauth_tokens_for_client(&self, client_id: &str) -> Result<Vec<AccessToken>>;
}
#[async_trait]
pub trait OAuthAuthorizationStore: Send + Sync {
async fn store_authorization_code(&mut self, code: AuthorizationCode) -> Result<()>;
async fn consume_authorization_code(&mut self, code: &str)
-> Result<Option<AuthorizationCode>>;
}
#[async_trait]
pub trait OAuthRefreshStore: Send + Sync {
async fn store_refresh_token(&mut self, token: RefreshToken) -> Result<()>;
async fn get_refresh_token(&self, token: &str) -> Result<Option<RefreshToken>>;
async fn rotate_refresh_token(
&mut self,
token: &str,
replacement: RefreshToken,
) -> Result<Option<RefreshToken>>;
async fn revoke_refresh_chain(&mut self, client_id: &str, user_name: &str) -> Result<u64>;
}
#[async_trait]
pub trait OAuthConsentStore: Send + Sync {
async fn record_consent(&mut self, consent: UserConsent) -> Result<UserConsent>;
async fn get_consent(&self, client_id: &str, user_name: &str) -> Result<Option<UserConsent>>;
async fn revoke_consent(&mut self, client_id: &str, user_name: &str) -> Result<bool>;
}