// pb_hooks/main.pb.js

routerAdd("GET", "/helloc", (c) => {
const info   = $apis.requestInfo(c);
// const admin  = c.get("admin")      // empty if not authenticated as admin
// const record = c.get("authRecord") // empty if not authenticated as regular auth record

// // alternatively, you can also read the auth state form the cached request info
// const info   = $apis.requestInfo(c);
// const admin1  = info.admin;      // empty if not authenticated as admin
// const record1 = info.authRecord; // empty if not authenticated as regular auth record
    // console.log(admin)
    // console.log(admin1)
    // console.log(record)
    // console.log(record1)

const isGuest = !admin && !record
})

routerAdd("GET", "/hello/:name", (c) => {
    let name = c.pathParam("name")

    return c.json(200, { "message": "Hello " + name })
})

onModelAfterUpdate((e) => {
    console.log("user updated...", e.model.get("email"))
}, "users")

// fires only for "users" and "managers" auth collections
onRecordAuthRequest((e) => {
    // console.log(JSON.stringify(e.httpContext))
    // console.log(JSON.stringify(e.record))
    console.log(e.token)
    console.log(e.meta)
}, "users", "managers")

// cronjob prints "Hello!" every 2 minutes
// cronAdd("hello", "*/2 * * * *", () => {
    // console.log("Hello!")
// })

