import { DrizzleClient } from '../../types/drizzle.js';
import { DrizzleTransaction } from '../events/event-bus.protocol.js';
import { BridgeDeliveryRecord } from './bridge-delivery.schema.js';
import { IJobBridge, BridgeDeliveryInsert, StatusHistogram } from './bridge.protocol.js';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/pg-core';
import 'drizzle-orm';
import '../events/event-registry.js';

declare class DrizzleBridgeDeliveryRepo implements IJobBridge {
    private readonly db;
    /**
     * Site (c) of the three ADR-023 §Multi-tenancy enforcement sites.
     * `@Optional()` so unit tests / non-bridge mounts that don't provide
     * the token still construct the repo cleanly; defaults to `false`,
     * which makes `assertTenantId` a no-op.
     */
    private readonly multiTenant;
    constructor(db: DrizzleClient, 
    /**
     * Site (c) of the three ADR-023 §Multi-tenancy enforcement sites.
     * `@Optional()` so unit tests / non-bridge mounts that don't provide
     * the token still construct the repo cleanly; defaults to `false`,
     * which makes `assertTenantId` a no-op.
     */
    multiTenant?: boolean);
    insertDelivery(row: BridgeDeliveryInsert, tx?: DrizzleTransaction): Promise<void>;
    findDelivery(eventId: string, triggerId: string): Promise<BridgeDeliveryRecord | null>;
    findDeliveryById(id: string): Promise<BridgeDeliveryRecord | null>;
    markDelivered(id: string, userRunId: string, tx?: DrizzleTransaction): Promise<void>;
    markSkipped(id: string, reason: string, tx?: DrizzleTransaction): Promise<void>;
    markFailed(id: string, error: Record<string, unknown>, tx?: DrizzleTransaction): Promise<void>;
    /**
     * Observability read — see `IJobBridge.getStatusHistogram` JSDoc for the
     * tenant-filter and windowHours contract.
     *
     * Tenant-filter note: this method intentionally does NOT call
     * `assertTenantId`. The write methods on this repo (`insertDelivery`)
     * treat `tenantId === undefined` as a misconfiguration and fail fast.
     * Reads are different — `undefined` is the supported "cross-tenant
     * admin view" mode that OBS-5 uses to render a framework-wide health
     * panel. Callers that need strict tenant scoping pass an explicit
     * string or `null`.
     *
     * Cast note: `count(*)::int` is applied in SQL so the node-pg driver
     * returns a `number` instead of the default `bigint → string` for
     * `count(*)`. Don't relax this cast — consumers (and the protocol)
     * type the result as `number`.
     */
    getStatusHistogram(windowHours: number, tenantId?: string | null): Promise<StatusHistogram>;
}

export { DrizzleBridgeDeliveryRepo };
