import * as _lock_sdk_core from '@lock-sdk/core';

declare enum IPFilterEventType {
    IP_BLOCKED = "ip.blocked",
    IP_ALLOWED = "ip.allowed",
    IP_FILTER_ERROR = "ip.error"
}
type IPStorage = 'memory' | 'redis' | 'upstash';
interface IPFilterConfig {
    mode: 'blacklist' | 'whitelist';
    ipAddresses: string[];
    storage?: IPStorage;
    ipHeaders?: string[];
    useRemoteAddress?: boolean;
    blockStatusCode?: number;
    blockMessage?: string;
    cacheTtl?: number;
    cacheSize?: number;
    failBehavior?: 'open' | 'closed';
    logFunction?: (message: string, data?: any) => void;
    logAllowed?: boolean;
    logBlocked?: boolean;
    redis?: {
        url?: string;
        host?: string;
        port?: number;
        username?: string;
        password?: string;
        database?: number;
        keyPrefix?: string;
    };
    upstash?: {
        url: string;
        token: string;
        keyPrefix?: string;
    };
}

declare function extractIp(req: any, ipHeaders?: string[], useRemoteAddress?: boolean): string | null;
declare function cleanIp(ip: string): string;

declare function ipInCidr(ip: string, cidr: string): boolean;
declare function ipEquals(ip1: string, ip2: string): boolean;
declare function isIpInList(ip: string, list: string[]): boolean;
declare function normalizeIp(ip: string): string | null;
declare function isValidIpOrCidr(input: string): boolean;

declare class MemoryIPCacheStore implements IPCacheStore {
    private cache;
    constructor(config: IPFilterConfig);
    init(): Promise<void>;
    get(key: string): Promise<boolean | null>;
    set(key: string, value: boolean): Promise<void>;
    close(): Promise<void>;
}

declare class RedisIPCacheStore implements IPCacheStore {
    private client;
    private keyPrefix;
    private config;
    private ttl;
    constructor(config: IPFilterConfig);
    init(): Promise<void>;
    get(key: string): Promise<boolean | null>;
    set(key: string, value: boolean): Promise<void>;
    close(): Promise<void>;
}

declare class UpstashIPCacheStore implements IPCacheStore {
    private client;
    private keyPrefix;
    private config;
    private ttl;
    constructor(config: IPFilterConfig);
    init(): Promise<void>;
    get(key: string): Promise<boolean | null>;
    set(key: string, value: boolean): Promise<void>;
    close(): Promise<void>;
}

interface IPCacheStore {
    init(): Promise<void>;
    get(key: string): Promise<boolean | null>;
    set(key: string, value: boolean): Promise<void>;
    close(): Promise<void>;
}
declare function createCacheStore(config: IPFilterConfig): Promise<IPCacheStore>;

declare const ipFilter: (config?: Partial<IPFilterConfig> | undefined) => _lock_sdk_core.SecurityModule;

export { type IPCacheStore, type IPFilterConfig, IPFilterEventType, type IPStorage, MemoryIPCacheStore, RedisIPCacheStore, UpstashIPCacheStore, cleanIp, createCacheStore, extractIp, ipEquals, ipFilter, ipInCidr, isIpInList, isValidIpOrCidr, normalizeIp };
