use owo_colors::OwoColorize;
use crate::client::ApiClient;
use crate::config::PartiriConfig;
use crate::error::Result;
use crate::output::format_datetime;
const LINES: usize = 35;
pub fn run(client: &ApiClient, config: &PartiriConfig) -> Result<()> {
let id = config.id_or_err()?;
let deploy_tag = config.deploy_tag.as_deref().ok_or(
"No deploy_tag found in config.\n Run 'partiri service pull' to refresh it after your latest deployment.",
)?;
let resp = client.read_service_logs(id, Some(deploy_tag))?;
if resp.logs.is_empty() {
println!("{}", "No logs in the last hour.".dimmed());
return Ok(());
}
let lines: Vec<_> = resp.logs.iter().rev().take(LINES).collect();
println!();
for line in lines.into_iter().rev() {
let ts = format_datetime(&line.timestamp);
println!(" {} {}", ts.dimmed(), line.message);
}
println!();
Ok(())
}