import { Request, Response, NextFunction } from 'express';
import { WhoIsResponse } from 'tailscale-local-api';
import { TailscaleCapabilitySchema } from './tailscale/schema.cjs';
import 'zod';

declare module "express-serve-static-core" {
    interface Request {
        tailscaleUser?: WhoIsResponse["userProfile"] & {
            capabilities: TailscaleCapabilitySchema;
        };
    }
}
type RequestWithTailscaleUser = Request & {
    tailscaleUser?: WhoIsResponse["userProfile"] & {
        capabilities: TailscaleCapabilitySchema;
    };
};
interface TailscaleAuthMiddlewareOptions {
    /**
     * The path to the tailscaled unix socket.
     * By default will look for common location on specific platforms.
     *
     * Unless you're running tailscale in a special way, you probably don't need to set this.
     * @example '/var/run/tailscale/tailscaled.sock'
     */
    socketPath?: string;
    /**
     * If true, will only use the unix socket to connect to tailscaled.
     * If false, will use the localhost TCP port to connect to tailscaled.
     *
     * Unless you're running tailscale in a special way, you probably don't need to set this.
     *
     * @default false
     */
    useSocketOnly?: boolean;
    /**
     * Whether to enable debug mode.
     * If enabled, the middleware will log debug information to the console.
     *
     * @default false
     */
    debug?: boolean;
    /**
     * The capabilities namespace to use for the Tailscale Grants.
     * If not set, the middleware will assume the user has access to every method on every route.
     *
     * @example
     * Set capabilitiesNamespace as "test.com/cap/express" for grants:
     * ```json
     * "grants": [{
     *   "src": ["user@example.com"],
     *   "dst": ["*"],
     *   "app": {
     *     "test.com/cap/express": [
     *       {
     *         "routes": [
     *           {"route": "/api", "methods": ["*"]},
     *           {"route": "/api/**", "methods": ["GET", "POST"]}
     *         ]
     *       }
     *     ]
     *   }
     * }]
     * ```
     */
    capabilitiesNamespace?: string;
}
declare const createTailscaleAuthMw: (options?: TailscaleAuthMiddlewareOptions) => (req: Request, res: Response, next: NextFunction) => Promise<void>;

export { type RequestWithTailscaleUser, type TailscaleAuthMiddlewareOptions, createTailscaleAuthMw };
