use puniyu_plugin::{app_name, app_version};
use puniyu_plugin::prelude::*;
use puniyu_system_info::SystemInfo;

#[command(name = "state")]
async fn state(ctx: &MessageContext<'_>) -> puniyu_plugin::result::Result<CommandAction> {
    let status = SystemInfo::process();
    let days = status.run_time / 86400;
    let hours = (status.run_time % 86400) / 3600;
    let minutes = (status.run_time % 3600) / 60;
    let seconds = status.run_time % 60;

    let info_text = format!(
        "------应用状态------\n\
        框架名称: {}\n\
        当前版本: v{}\n\
        内存占用：{:.2}MB\n\
        运行时间：{}天{}小时{}分钟{}秒",
        app_name(),
        app_version(),
        status.used_memory,
        days,
        hours,
        minutes,
        seconds
    );
    ctx.reply(Message::from(info_text.as_str())).await?;
    Ok(CommandAction::Done)
}
