// Keto namespaces owned by sunbeam-g2v. Mounted into the workspace keto by
// `sunbeam.workspace.yaml` alongside the other projects' namespace files;
// Keto reads them all from `/etc/namespaces/` (directory mode).

import { Namespace, Context } from "@ory/keto-namespace-types"

// Re-declared here so this file parses standalone. The `User` namespace is
// also declared in `sbbb.config.ts` — Keto v26 directory mode merges files
// without conflict.
class User implements Namespace {}

// Generic test namespace consumed by sunbeam-g2v integration tests
// (`libs/sunbeam-g2v/tests/keto_integration.rs`). Object IDs are UUIDs minted
// per-test so concurrent runs against the shared keto don't collide.
class G2vTest implements Namespace {
  related: {
    readers: User[]
    writers: User[]
  }
  permits = {
    read: (ctx: Context) =>
      this.related.readers.includes(ctx.subject) ||
      this.related.writers.includes(ctx.subject),
    write: (ctx: Context) => this.related.writers.includes(ctx.subject),
  }
}
