import type { User } from 'types';
import { Hono } from 'hono';

export type HonoVariables = {
  body: Record<string, unknown>;
  origin: string;
  /**
   * The authenticated account, plus — on routes that resolve it — the home directory this request is
   * confined to.
   *
   * `homeDir` is optional because only the file browser's `confineToHome` middleware sets it, and it lives
   * on `user` rather than in its own variable for a blunt reason: `getRootDir(user, root)` is called from
   * fifteen places in that router, and the cost of missing one is serving the OWNER'S home to a member.
   * Carrying it on the object those call sites already receive means none of them can forget.
   */
  user: User & { homeDir?: string };
};

export const createRouter = () => new Hono<{ Variables: HonoVariables }>();
