import { JSONObject, Timestamp, XID } from './index';
export interface BaseEvent {
    type: string;
    timestamp: Timestamp;
    id: XID;
    metadata?: JSONObject;
}
export type AuthEventType = 'auth.signIn.attempt' | 'auth.signIn.success' | 'auth.signIn.failure' | 'auth.signUp.attempt' | 'auth.signUp.success' | 'auth.signUp.failure' | 'auth.signOut.success' | 'auth.session.created' | 'auth.session.refreshed' | 'auth.session.expired' | 'auth.session.terminated' | 'auth.mfa.enabled' | 'auth.mfa.disabled' | 'auth.mfa.challenge.sent' | 'auth.mfa.challenge.success' | 'auth.mfa.challenge.failure' | 'auth.passkey.registered' | 'auth.passkey.removed' | 'auth.passkey.used' | 'auth.oauth.connected' | 'auth.oauth.disconnected' | 'auth.password.changed' | 'auth.password.reset.requested' | 'auth.password.reset.completed' | 'auth.email.verification.sent' | 'auth.email.verification.success' | 'auth.phone.verification.sent' | 'auth.phone.verification.success' | 'auth.magic_link.sent' | 'auth.magic_link.used';
export interface AuthEvent extends BaseEvent {
    type: AuthEventType;
    userId?: XID;
    organizationId?: XID;
    sessionId?: XID;
    ipAddress?: string;
    userAgent?: string;
    authMethod?: string;
    provider?: string;
    success: boolean;
    reason?: string;
    details?: JSONObject;
}
export type UserEventType = 'user.created' | 'user.updated' | 'user.deleted' | 'user.activated' | 'user.deactivated' | 'user.blocked' | 'user.unblocked' | 'user.profile.updated' | 'user.email.changed' | 'user.phone.changed' | 'user.username.changed' | 'user.role.assigned' | 'user.role.removed' | 'user.permission.granted' | 'user.permission.revoked' | 'user.impersonation.started' | 'user.impersonation.ended';
export interface UserEvent extends BaseEvent {
    type: UserEventType;
    userId: XID;
    organizationId?: XID;
    targetUserId?: XID;
    performedBy?: XID;
    changes?: JSONObject;
    previousValues?: JSONObject;
    newValues?: JSONObject;
}
export type OrganizationEventType = 'organization.created' | 'organization.updated' | 'organization.deleted' | 'organization.activated' | 'organization.deactivated' | 'organization.member.added' | 'organization.member.removed' | 'organization.member.role.changed' | 'organization.member.status.changed' | 'organization.invitation.created' | 'organization.invitation.accepted' | 'organization.invitation.expired' | 'organization.invitation.revoked' | 'organization.settings.updated' | 'organization.domain.added' | 'organization.domain.verified' | 'organization.domain.removed' | 'organization.sso.enabled' | 'organization.sso.disabled' | 'organization.sso.configured' | 'organization.billing.updated' | 'organization.plan.changed' | 'organization.ownership.transferred';
export interface OrganizationEvent extends BaseEvent {
    type: OrganizationEventType;
    organizationId: XID;
    userId?: XID;
    targetUserId?: XID;
    performedBy?: XID;
    changes?: JSONObject;
    previousValues?: JSONObject;
    newValues?: JSONObject;
}
export type SessionEventType = 'session.created' | 'session.refreshed' | 'session.updated' | 'session.expired' | 'session.terminated' | 'session.activity.recorded' | 'session.suspicious.activity' | 'session.device.changed' | 'session.location.changed' | 'session.concurrent.limit.exceeded';
export interface SessionEvent extends BaseEvent {
    type: SessionEventType;
    sessionId: XID;
    userId: XID;
    organizationId?: XID;
    ipAddress?: string;
    userAgent?: string;
    deviceInfo?: JSONObject;
    locationInfo?: JSONObject;
    reason?: string;
    details?: JSONObject;
}
export type SecurityEventType = 'security.login.failure.threshold' | 'security.account.locked' | 'security.account.unlocked' | 'security.password.breach.detected' | 'security.suspicious.login' | 'security.device.new' | 'security.location.new' | 'security.api.rate.limit.exceeded' | 'security.permission.escalation' | 'security.data.export' | 'security.admin.action' | 'security.configuration.changed';
export interface SecurityEvent extends BaseEvent {
    type: SecurityEventType;
    userId?: XID;
    organizationId?: XID;
    sessionId?: XID;
    severity: 'low' | 'medium' | 'high' | 'critical';
    riskScore?: number;
    ipAddress?: string;
    userAgent?: string;
    automated: boolean;
    resolved: boolean;
    resolvedAt?: Timestamp;
    resolvedBy?: XID;
    actionTaken?: string;
    details?: JSONObject;
}
export type SystemEventType = 'system.startup' | 'system.shutdown' | 'system.error' | 'system.maintenance.started' | 'system.maintenance.completed' | 'system.backup.started' | 'system.backup.completed' | 'system.update.started' | 'system.update.completed' | 'system.configuration.changed';
export interface SystemEvent extends BaseEvent {
    type: SystemEventType;
    severity: 'info' | 'warning' | 'error' | 'critical';
    component?: string;
    version?: string;
    details?: JSONObject;
}
export type BillingEventType = 'billing.subscription.created' | 'billing.subscription.updated' | 'billing.subscription.canceled' | 'billing.payment.succeeded' | 'billing.payment.failed' | 'billing.invoice.created' | 'billing.invoice.paid' | 'billing.invoice.overdue' | 'billing.trial.started' | 'billing.trial.ended' | 'billing.seat.added' | 'billing.seat.removed' | 'billing.usage.threshold.exceeded';
export interface BillingEvent extends BaseEvent {
    type: BillingEventType;
    organizationId: XID;
    customerId?: string;
    subscriptionId?: string;
    invoiceId?: string;
    amount?: number;
    currency?: string;
    details?: JSONObject;
}
export type IntegrationEventType = 'integration.webhook.sent' | 'integration.webhook.failed' | 'integration.api.key.created' | 'integration.api.key.revoked' | 'integration.sso.login' | 'integration.sso.failure' | 'integration.directory.sync' | 'integration.audit.export';
export interface IntegrationEvent extends BaseEvent {
    type: IntegrationEventType;
    organizationId?: XID;
    integrationId?: XID;
    webhookUrl?: string;
    statusCode?: number;
    responseTime?: number;
    retryCount?: number;
    details?: JSONObject;
}
export type FrankAuthEvent = AuthEvent | UserEvent | OrganizationEvent | SessionEvent | SecurityEvent | SystemEvent | BillingEvent | IntegrationEvent;
export type EventHandler<T extends FrankAuthEvent = FrankAuthEvent> = (event: T) => void | Promise<void>;
export interface EventListener {
    id: XID;
    eventType: string;
    handler: EventHandler;
    once?: boolean;
    organizationId?: XID;
    userId?: XID;
}
export interface EventEmitter {
    on<T extends FrankAuthEvent>(eventType: T['type'], handler: EventHandler<T>): () => void;
    once<T extends FrankAuthEvent>(eventType: T['type'], handler: EventHandler<T>): () => void;
    off<T extends FrankAuthEvent>(eventType: T['type'], handler: EventHandler<T>): void;
    removeAllListeners(eventType?: string): void;
    emit<T extends FrankAuthEvent>(event: T): void;
    listenerCount(eventType: string): number;
    listeners(eventType: string): EventHandler[];
}
export interface EventStore {
    store(event: FrankAuthEvent): Promise<void>;
    query(filters: EventQueryFilters): Promise<FrankAuthEvent[]>;
    getById(eventId: XID): Promise<FrankAuthEvent | null>;
    delete(eventId: XID): Promise<void>;
    cleanup(olderThan: Timestamp): Promise<number>;
}
export interface EventQueryFilters {
    eventTypes?: string[];
    userId?: XID;
    organizationId?: XID;
    sessionId?: XID;
    startTime?: Timestamp;
    endTime?: Timestamp;
    severity?: string[];
    limit?: number;
    offset?: number;
    sortBy?: 'timestamp' | 'type' | 'severity';
    sortOrder?: 'asc' | 'desc';
}
export interface EventSubscription {
    id: XID;
    eventTypes: string[];
    filters?: EventSubscriptionFilters;
    endpoint?: string;
    headers?: Record<string, string>;
    active: boolean;
    createdAt: Timestamp;
    updatedAt: Timestamp;
}
export interface EventSubscriptionFilters {
    organizationId?: XID;
    userId?: XID;
    severity?: string[];
    excludeEventTypes?: string[];
}
export interface WebhookEventPayload {
    id: XID;
    event: FrankAuthEvent;
    organizationId?: XID;
    timestamp: Timestamp;
    signature: string;
    attempt: number;
}
export interface EventAnalytics {
    organizationId?: XID;
    timeRange: {
        start: Timestamp;
        end: Timestamp;
    };
    totalEvents: number;
    eventTypeBreakdown: Record<string, number>;
    activeUsers: number;
    newUsers: number;
    loginAttempts: number;
    successfulLogins: number;
    failedLogins: number;
    mfaUsage: number;
    securityEvents: number;
    blockedAttempts: number;
    suspiciousActivity: number;
    timeSeriesData: Array<{
        timestamp: Timestamp;
        eventCount: number;
        userCount: number;
        securityEventCount: number;
    }>;
}
export interface EventConfig {
    storage: {
        enabled: boolean;
        retentionDays: number;
        compressionEnabled: boolean;
    };
    streaming: {
        enabled: boolean;
        batchSize: number;
        flushInterval: number;
    };
    webhooks: {
        enabled: boolean;
        maxRetries: number;
        timeoutMs: number;
        signatureSecret: string;
    };
    analytics: {
        enabled: boolean;
        aggregationInterval: number;
        realTimeEnabled: boolean;
    };
    security: {
        encryptionEnabled: boolean;
        sanitizeUserData: boolean;
        allowEventExport: boolean;
    };
}
export interface RealtimeEventSubscription {
    id: XID;
    eventTypes: string[];
    callback: EventHandler;
    filters?: EventSubscriptionFilters;
    active: boolean;
}
export interface EventContext {
    emitter: EventEmitter;
    subscribe: <T extends FrankAuthEvent>(eventType: T['type'], handler: EventHandler<T>, options?: {
        once?: boolean;
        organizationId?: XID;
    }) => () => void;
    emit: <T extends FrankAuthEvent>(event: T) => void;
    getEventHistory: (filters: EventQueryFilters) => Promise<FrankAuthEvent[]>;
    getAnalytics: (timeRange: {
        start: Timestamp;
        end: Timestamp;
    }) => Promise<EventAnalytics>;
}
export type EventMiddleware = (event: FrankAuthEvent, next: () => void) => void | Promise<void>;
export interface EventPipeline {
    use(middleware: EventMiddleware): void;
    process(event: FrankAuthEvent): Promise<void>;
    configure(config: {
        errorHandling: 'throw' | 'log' | 'ignore';
        timeout?: number;
        retries?: number;
    }): void;
}
//# sourceMappingURL=events.d.ts.map