import { z } from "zod";
export interface WebhookConfig {
    maxRetries: number;
    retryDelayMs: number;
    maxDelayMs?: number;
    backoffMultiplier?: number;
    jitter?: boolean;
    timeoutMs: number;
    enableSecurity: boolean;
    secretKey?: string;
    algorithm?: "sha256" | "sha1";
    signatureHeader?: string;
    signaturePrefix?: string;
    enabledEvents: WebhookEventType[];
    batchSize: number;
    batchTimeoutMs: number;
}
export declare enum WebhookEventType {
    MESSAGE_SENT = "message.sent",
    MESSAGE_DELIVERED = "message.delivered",
    MESSAGE_FAILED = "message.failed",
    MESSAGE_CLICKED = "message.clicked",
    MESSAGE_READ = "message.read",
    TEMPLATE_CREATED = "template.created",
    TEMPLATE_APPROVED = "template.approved",
    TEMPLATE_REJECTED = "template.rejected",
    TEMPLATE_UPDATED = "template.updated",
    TEMPLATE_DELETED = "template.deleted",
    CHANNEL_CREATED = "channel.created",
    CHANNEL_VERIFIED = "channel.verified",
    SENDER_NUMBER_ADDED = "sender_number.added",
    SENDER_NUMBER_VERIFIED = "sender_number.verified",
    QUOTA_WARNING = "system.quota_warning",
    QUOTA_EXCEEDED = "system.quota_exceeded",
    PROVIDER_ERROR = "system.provider_error",
    SYSTEM_MAINTENANCE = "system.maintenance",
    ANOMALY_DETECTED = "analytics.anomaly_detected",
    THRESHOLD_EXCEEDED = "analytics.threshold_exceeded"
}
export interface WebhookEvent<T = any> {
    id: string;
    type: WebhookEventType;
    timestamp: Date;
    data: T;
    metadata: {
        providerId?: string;
        channelId?: string;
        templateId?: string;
        messageId?: string;
        userId?: string;
        organizationId?: string;
        correlationId?: string;
        retryCount?: number;
    };
    version: string;
}
export interface WebhookEndpoint {
    id: string;
    url: string;
    name?: string;
    description?: string;
    active: boolean;
    events: WebhookEventType[];
    headers?: Record<string, string>;
    secret?: string;
    retryConfig?: {
        maxRetries: number;
        retryDelayMs: number;
        backoffMultiplier: number;
    };
    filters?: {
        providerId?: string[];
        channelId?: string[];
        templateId?: string[];
    };
    createdAt: Date;
    updatedAt: Date;
    lastTriggeredAt?: Date;
    status: "active" | "inactive" | "error" | "suspended";
}
export interface WebhookDelivery {
    id: string;
    endpointId: string;
    eventId: string;
    /**
     * Optional event type for filtering/stats.
     * (Helpful because `payload` is a JSON string and timestamps need revival when parsed.)
     */
    eventType?: WebhookEventType;
    url: string;
    httpMethod: "POST" | "PUT" | "PATCH";
    headers: Record<string, string>;
    payload: string;
    attempts: WebhookAttempt[];
    status: "pending" | "success" | "failed" | "exhausted";
    createdAt: Date;
    completedAt?: Date;
    nextRetryAt?: Date;
}
export interface WebhookAttempt {
    attemptNumber: number;
    timestamp: Date;
    httpStatus?: number;
    responseBody?: string;
    responseHeaders?: Record<string, string>;
    error?: string;
    latencyMs: number;
}
export interface WebhookSecurity {
    algorithm: "sha256" | "sha1";
    header: string;
    prefix?: string;
}
export interface WebhookBatch {
    id: string;
    endpointId: string;
    events: WebhookEvent[];
    createdAt: Date;
    scheduledAt: Date;
    status: "pending" | "processing" | "completed" | "failed";
}
export interface WebhookStats {
    endpointId: string;
    timeRange: {
        start: Date;
        end: Date;
    };
    totalDeliveries: number;
    successfulDeliveries: number;
    failedDeliveries: number;
    averageLatencyMs: number;
    successRate: number;
    eventBreakdown: Record<WebhookEventType, number>;
    errorBreakdown: Record<string, number>;
}
export interface WebhookTestResult {
    endpointId: string;
    url: string;
    success: boolean;
    httpStatus?: number;
    responseTime: number;
    error?: string;
    testedAt: Date;
}
export declare const WebhookEventSchema: z.ZodObject<{
    id: z.ZodString;
    type: z.ZodString;
    timestamp: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDate>;
    data: z.ZodAny;
    metadata: z.ZodObject<{
        providerId: z.ZodOptional<z.ZodString>;
        channelId: z.ZodOptional<z.ZodString>;
        templateId: z.ZodOptional<z.ZodString>;
        messageId: z.ZodOptional<z.ZodString>;
        userId: z.ZodOptional<z.ZodString>;
        organizationId: z.ZodOptional<z.ZodString>;
        correlationId: z.ZodOptional<z.ZodString>;
        retryCount: z.ZodOptional<z.ZodNumber>;
    }, z.core.$strip>;
    version: z.ZodString;
}, z.core.$strip>;
export declare const WebhookEndpointSchema: z.ZodObject<{
    id: z.ZodString;
    url: z.ZodString;
    name: z.ZodOptional<z.ZodString>;
    description: z.ZodOptional<z.ZodString>;
    active: z.ZodBoolean;
    events: z.ZodArray<z.ZodString>;
    headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
    secret: z.ZodOptional<z.ZodString>;
    retryConfig: z.ZodOptional<z.ZodObject<{
        maxRetries: z.ZodNumber;
        retryDelayMs: z.ZodNumber;
        backoffMultiplier: z.ZodNumber;
    }, z.core.$strip>>;
    filters: z.ZodOptional<z.ZodObject<{
        providerId: z.ZodOptional<z.ZodArray<z.ZodString>>;
        channelId: z.ZodOptional<z.ZodArray<z.ZodString>>;
        templateId: z.ZodOptional<z.ZodArray<z.ZodString>>;
    }, z.core.$strip>>;
    createdAt: z.ZodDate;
    updatedAt: z.ZodDate;
    lastTriggeredAt: z.ZodOptional<z.ZodDate>;
    status: z.ZodEnum<{
        active: "active";
        inactive: "inactive";
        error: "error";
        suspended: "suspended";
    }>;
}, z.core.$strip>;
export declare const WebhookDeliverySchema: z.ZodObject<{
    id: z.ZodString;
    endpointId: z.ZodString;
    eventId: z.ZodString;
    eventType: z.ZodOptional<z.ZodString>;
    url: z.ZodString;
    httpMethod: z.ZodEnum<{
        POST: "POST";
        PUT: "PUT";
        PATCH: "PATCH";
    }>;
    headers: z.ZodRecord<z.ZodString, z.ZodString>;
    payload: z.ZodString;
    attempts: z.ZodArray<z.ZodObject<{
        attemptNumber: z.ZodNumber;
        timestamp: z.ZodDate;
        httpStatus: z.ZodOptional<z.ZodNumber>;
        responseBody: z.ZodOptional<z.ZodString>;
        responseHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
        error: z.ZodOptional<z.ZodString>;
        latencyMs: z.ZodNumber;
    }, z.core.$strip>>;
    status: z.ZodEnum<{
        pending: "pending";
        success: "success";
        failed: "failed";
        exhausted: "exhausted";
    }>;
    createdAt: z.ZodDate;
    completedAt: z.ZodOptional<z.ZodDate>;
    nextRetryAt: z.ZodOptional<z.ZodDate>;
}, z.core.$strip>;
export type WebhookEventData = z.infer<typeof WebhookEventSchema>;
export type WebhookEndpointData = z.infer<typeof WebhookEndpointSchema>;
export type WebhookDeliveryData = z.infer<typeof WebhookDeliverySchema>;
