mod commons;
mod db;
mod protocols;
mod router;

#[cfg(test)]
mod tests {
    use std::time::{SystemTime, UNIX_EPOCH};

    use crate::commons::utils;

    async fn init_db() {
        _ = crate::db::init_db().await;
    }

    #[tokio::test]
    async fn test_db() {
        _ = init_db().await;
        // if let Ok(res) =
        //     crate::db::db_query("select * from tb_user where id=?", vec![json!("123")]).await
        // {
        //     dbg!(&res);
        // }

        // let game = crate::db::models::game::Game {
        //     event_date: "2026-05-25".parse().unwrap(),
        //     wechat_id: "test_wechat_id".to_string(),
        //     nickname: Some("test_nickname".to_string()),
        //     avatar: Some("test_avatar".to_string()),
        //     round_num: 1,
        //     item_num: 2,
        //     score: 100,
        //     create_date: None,
        // };
        // let res = game.insert().await;
        // dbg!(&res);

        let res = crate::db::models::manager::Manager::Login(
            crate::db::models::manager::ManagerLogin::user(
                "admin".to_string(),
                "123456".to_string(),
            ),
        )
        .await;
        dbg!(&res);
    }

    fn test_userid() -> String {
        let ts = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .map(|value| value.as_millis())
            .unwrap_or(0);
        format!("test_userid_{ts}")
    }

    #[tokio::test]
    async fn test_current_timestamp() {
        let ts = utils::get_current_timestamp();
        dbg!(&ts);
        let ts = utils::add_second(ts, 3);
        dbg!(&ts);

        let now = chrono::Local::now();
        println!("{}", now.format("%Y-%m-%d %H:%M:%S"));

        let utc_ts = chrono::Utc::now().timestamp();

        let local_time = chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string();

        println!("时间戳: {}", utc_ts);
        println!("本地时间: {}", local_time);
    }
}
