import { RouteGuard } from './RouteGuard';
import { PathnameInterpreter } from './PathnameInterpreter';
import { RouteCatalog } from './RouteCatalog';
import { RouteAccessPolicy } from './RouteAccessPolicy';
import { ReturnToSanitizer } from './ReturnToSanitizer';
import { RoutePathBuilder } from './RoutePathBuilder';
import { AuthRedirectBuilder } from './AuthRedirectBuilder';
import { SessionGateway } from '../gateways/SessionGateway';

/**
 * Factory function to create a RouteGuard instance with all dependencies
 * 
 * Usage:
 * ```typescript
 * const guard = createRouteGuard();
 * await guard.enforce({ pathname: '/dashboard' });
 * ```
 * 
 * @returns RouteGuard instance configured with all required dependencies
 */
export function createRouteGuard(): RouteGuard {
  const catalog = new RouteCatalog();
  const interpreter = new PathnameInterpreter();
  const policy = new RouteAccessPolicy(catalog);
  const sanitizer = new ReturnToSanitizer();
  const pathBuilder = new RoutePathBuilder();
  const redirectBuilder = new AuthRedirectBuilder(policy, sanitizer, pathBuilder, interpreter);
  const gateway = new SessionGateway();
  
  return new RouteGuard(interpreter, policy, gateway, redirectBuilder);
}