use async_trait::async_trait;
use oriko_services::{GmailClient, GmailClientBuilder, TokenProvider};

struct MyTokenProvider {
    access_token: String,
}

#[async_trait]
impl TokenProvider for MyTokenProvider {
    async fn get_access_token(&self) -> Result<String, String> {
        Ok(self.access_token.clone())
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create token provider
    let token_provider = Box::new(MyTokenProvider {
        access_token: "your_access_token".to_string(),
    });

    // Build client
    let client = GmailClient::builder()
        .token_provider(token_provider)
        .build()?;

    // Fetch messages
    let messages = client.fetch_messages(Some(10)).await?;
    println!("Fetched {} messages", messages.len());

    // Fetch and parse a message
    if let Some(message_id) = messages.first() {
        let full_message = client.fetch_message(&message_id.id).await?;
        let parsed = client.parse_email(&full_message)?;

        println!("Subject: {:?}", parsed.subject);
        println!("From: {:?}", parsed.from_email);
    }

    Ok(())
}
