use anyhow::Result;
use serde_json::Value;

use super::auth;
use crate::lexicons::app_bsky_feed;
use crate::xrpc::XrpcClient;

/// Get timeline (JSON output)
pub async fn timeline(limit: u32) -> Result<()> {
    let session = auth::refresh_session().await?;
    let pds = session.pds.as_deref().unwrap_or("bsky.social");
    let client = XrpcClient::new(pds);
    let limit_str = limit.to_string();

    let body: Value = client
        .query_auth(
            &app_bsky_feed::GET_TIMELINE,
            &[("limit", &limit_str)],
            &session.access_jwt,
        )
        .await?;

    println!("{}", serde_json::to_string_pretty(&body)?);
    Ok(())
}
