/**
 * Entity Route Handler
 *
 * Base handler for entity API routes with automatic permission checking,
 * field filtering, and standardized responses.
 */
import { NextRequest, NextResponse } from 'next/server';
import type { CRUDOperation, EntityConfig } from '../entities/types';
/**
 * Entity handler context
 */
export interface EntityHandlerContext {
    user: {
        id: string;
        email: string;
        role: string;
    };
    entity: EntityConfig;
    request: NextRequest;
    pagination?: {
        page: number;
        limit: number;
        offset: number;
    };
}
/**
 * Entity handler options
 */
export interface EntityHandlerOptions {
    allowMetadata?: boolean;
    customValidation?: (context: EntityHandlerContext) => Promise<{
        valid: boolean;
        error?: string;
    }>;
}
/**
 * CRUD handler functions
 */
export interface EntityCRUDHandlers {
    list?: (context: EntityHandlerContext) => Promise<{
        data: Array<Record<string, unknown>>;
        total: number;
    }>;
    create?: (context: EntityHandlerContext, data: Record<string, unknown>) => Promise<Record<string, unknown>>;
    read?: (context: EntityHandlerContext, id: string) => Promise<Record<string, unknown> | null>;
    update?: (context: EntityHandlerContext, id: string, data: Record<string, unknown>) => Promise<Record<string, unknown> | null>;
    delete?: (context: EntityHandlerContext, id: string) => Promise<boolean>;
}
/**
 * Legacy function - use createEntityListHandlers or createEntityDetailHandlers instead
 * @deprecated
 */
export declare function createEntityHandlers(entityName: string, handlers: EntityCRUDHandlers, options?: EntityHandlerOptions): {
    GET: (request: NextRequest) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: Record<string, unknown>[];
        info: {
            timestamp: string;
        };
    }>>;
    POST: (request: NextRequest) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: Record<string, unknown>;
        info: {
            timestamp: string;
        };
    }>>;
};
/**
 * Wrapper for entity auth - simplified without permissions
 */
export declare function withEntityAuth(entityName: string, action: CRUDOperation, options?: EntityHandlerOptions): <T extends unknown[]>(handler: (context: EntityHandlerContext, ...args: T) => Promise<NextResponse>) => (request: NextRequest, ...args: T) => Promise<NextResponse>;
/**
 * Create standardized CRUD handlers for an entity (list and create only)
 */
export declare function createEntityListHandlers(entityName: string, handlers: EntityCRUDHandlers, options?: EntityHandlerOptions): {
    GET: (request: NextRequest) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: Record<string, unknown>[];
        info: {
            timestamp: string;
        };
    }>>;
    POST: (request: NextRequest) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: Record<string, unknown>;
        info: {
            timestamp: string;
        };
    }>>;
};
/**
 * Create standardized CRUD handlers for entity detail routes (with [id])
 */
export declare function createEntityDetailHandlers(entityName: string, handlers: EntityCRUDHandlers, options?: EntityHandlerOptions): {
    GET: (request: NextRequest, routeContext: {
        params: Promise<{
            id: string;
        }>;
    }) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: Record<string, unknown>;
        info: {
            timestamp: string;
        };
    }>>;
    PATCH: (request: NextRequest, routeContext: {
        params: Promise<{
            id: string;
        }>;
    }) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: Record<string, unknown>;
        info: {
            timestamp: string;
        };
    }>>;
    DELETE: (request: NextRequest, routeContext: {
        params: Promise<{
            id: string;
        }>;
    }) => Promise<NextResponse<{
        success: boolean;
        error: string;
        code: string;
        details: unknown;
        info: {
            timestamp: string;
        };
    }> | NextResponse<{
        success: boolean;
        data: {
            success: boolean;
            id: string;
        };
        info: {
            timestamp: string;
        };
    }>>;
};
/**
 * Simple wrapper for single-action handlers
 */
export declare function withEntityAction(entityName: string, action: CRUDOperation, options?: EntityHandlerOptions): <T extends unknown[]>(handler: (context: EntityHandlerContext, ...args: T) => Promise<NextResponse>) => (request: NextRequest, ...args: T) => Promise<NextResponse>;
/**
 * Helper to create database query context with RLS
 */
export declare function createQueryContext(context: EntityHandlerContext): {
    userId: string;
    userRole: string;
    userFlags: any[];
    entityConfig: EntityConfig;
};
//# sourceMappingURL=entity-handler.d.ts.map