#[static_init::constructor(0)]
extern "C" fn _log_init() {
  log_init::init();
}

use anyhow::Result;
use aok::{OK, Void};
use site_log::{Ctx, HookLi, HookSlice, SiteLog, ctx};

#[derive(tosql::ToSql)]
pub struct User {
  pub id: u64,
}

#[linkme::distributed_slice]
pub static USER: HookLi<User>;

impl SiteLog for User {
  const TYPE_ID: u64 = 1;
  const HOOK: HookSlice<Self> = &USER;
}

#[linkme::distributed_slice(USER)]
pub fn test_abc(user: Ctx<User>) -> tokio::task::JoinHandle<Result<()>> {
  tokio::spawn(async move {
    println!(">>> USER ID {}", user.id);
    Ok(())
  })
}

#[tokio::test]
async fn test() -> Void {
  let ctx = ctx::Ctx::new("127.0.0.1".parse().unwrap(), 1, 1, 1);
  let user = User { id: 1 };
  user.site_log(ctx.into()).await?;
  OK
}
