import { Querier } from "@platform-modules/db";
//#region src/types.d.ts
type AuditEvent = {
  actorId?: string | null;
  actorType?: string | null;
  actorLabel?: string | null;
  action: string;
  entityType: string;
  entityId: string;
  metadata?: Record<string, unknown> | null;
  ip?: string | null;
  tenantId?: string | null;
};
type LogAuditResult = {
  logged: boolean;
  id?: string;
  error?: unknown;
};
type AuditRecord = {
  id: string;
  actorId: string | null;
  actorType: string | null;
  actorLabel: string | null;
  action: string;
  entityType: string;
  entityId: string;
  metadata: Record<string, unknown> | null;
  ip: string | null;
  tenantId: string | null;
  createdAt: Date;
};
type ListAuditFilter = {
  tenant?: string;
  actor?: string;
  entityType?: string;
  entityId?: string;
  action?: string;
  from?: Date;
  to?: Date;
  q?: string;
  limit?: number;
  cursor?: string;
};
type ListAuditResult = {
  items: AuditRecord[];
  nextCursor: string | null;
};
type AuditCursor = {
  createdAt: string;
  id: string;
};
//#endregion
//#region src/cursor.d.ts
declare function encodeCursor(row: {
  createdAt: Date;
  id: string;
}): string;
declare function decodeCursor(cursor: string): AuditCursor;
//#endregion
//#region src/errors.d.ts
declare class InvalidCursorError extends Error {
  readonly name = "InvalidCursorError";
  constructor();
}
//#endregion
//#region src/schema.d.ts
declare const auditLog: import("drizzle-orm/pg-core").PgTableWithColumns<{
  name: "audit_log";
  schema: undefined;
  columns: {
    id: import("drizzle-orm/pg-core").PgColumn<{
      name: "id";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgUUID";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: true;
      isAutoincrement: false;
      hasRuntimeDefault: true;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    actorId: import("drizzle-orm/pg-core").PgColumn<{
      name: "actor_id";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    actorType: import("drizzle-orm/pg-core").PgColumn<{
      name: "actor_type";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    actorLabel: import("drizzle-orm/pg-core").PgColumn<{
      name: "actor_label";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    action: import("drizzle-orm/pg-core").PgColumn<{
      name: "action";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    entityType: import("drizzle-orm/pg-core").PgColumn<{
      name: "entity_type";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    entityId: import("drizzle-orm/pg-core").PgColumn<{
      name: "entity_id";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    metadata: import("drizzle-orm/pg-core").PgColumn<{
      name: "metadata";
      tableName: "audit_log";
      dataType: "json";
      columnType: "PgJsonb";
      data: Record<string, unknown> | null;
      driverParam: unknown;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {
      $type: Record<string, unknown> | null;
    }>;
    ip: import("drizzle-orm/pg-core").PgColumn<{
      name: "ip";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    tenantId: import("drizzle-orm/pg-core").PgColumn<{
      name: "tenant_id";
      tableName: "audit_log";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    createdAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "created_at";
      tableName: "audit_log";
      dataType: "date";
      columnType: "PgTimestamp";
      data: Date;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: true;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
  };
  dialect: "pg";
}>;
declare const auditSchema: {
  auditLog: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "audit_log";
    schema: undefined;
    columns: {
      id: import("drizzle-orm/pg-core").PgColumn<{
        name: "id";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgUUID";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: true;
        isAutoincrement: false;
        hasRuntimeDefault: true;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      actorId: import("drizzle-orm/pg-core").PgColumn<{
        name: "actor_id";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      actorType: import("drizzle-orm/pg-core").PgColumn<{
        name: "actor_type";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      actorLabel: import("drizzle-orm/pg-core").PgColumn<{
        name: "actor_label";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      action: import("drizzle-orm/pg-core").PgColumn<{
        name: "action";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      entityType: import("drizzle-orm/pg-core").PgColumn<{
        name: "entity_type";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      entityId: import("drizzle-orm/pg-core").PgColumn<{
        name: "entity_id";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      metadata: import("drizzle-orm/pg-core").PgColumn<{
        name: "metadata";
        tableName: "audit_log";
        dataType: "json";
        columnType: "PgJsonb";
        data: Record<string, unknown> | null;
        driverParam: unknown;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {
        $type: Record<string, unknown> | null;
      }>;
      ip: import("drizzle-orm/pg-core").PgColumn<{
        name: "ip";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      tenantId: import("drizzle-orm/pg-core").PgColumn<{
        name: "tenant_id";
        tableName: "audit_log";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      createdAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "created_at";
        tableName: "audit_log";
        dataType: "date";
        columnType: "PgTimestamp";
        data: Date;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: true;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
    };
    dialect: "pg";
  }>;
};
type AuditSchema = typeof auditSchema;
//#endregion
//#region src/list-audit.d.ts
/**
 * List audit records, newest first, with keyset pagination (cursor = `(created_at_ms, id)`).
 *
 * `tenant` is OPTIONAL (single-tenant hosts store `tenant_id` null). When provided it
 * constrains correctly; when omitted the query spans ALL tenants — scoping is the host's
 * responsibility. On a multi-tenant audit surface, always pass `tenant` (fail-open default).
 */
declare function listAudit<S extends AuditSchema>(db: Querier<S>, filter?: ListAuditFilter): Promise<ListAuditResult>;
//#endregion
//#region src/log-audit.d.ts
/**
 * Append an audit record. **Never throws** — a write failure is swallowed and
 * returned as `{ logged: false, error }` so it cannot break the operation being logged.
 *
 * CONTRACT (boundary spec amendment B): because failures are swallowed, this is the
 * *decoupled* form — call it **after the business commit, or fire-and-forget**.
 * Do NOT call it inside the caller's business transaction: a failed insert aborts the
 * whole Postgres tx while the swallow hides it, so the mutation can commit with the
 * audit row silently dropped. For transaction-atomic audit, insert into the exported
 * `auditLog` schema directly within your own tx (a throw there correctly rolls back).
 */
declare function logAudit<S extends AuditSchema>(db: Querier<S>, event: AuditEvent): Promise<LogAuditResult>;
//#endregion
export { type AuditCursor, type AuditEvent, type AuditRecord, type AuditSchema, InvalidCursorError, type ListAuditFilter, type ListAuditResult, type LogAuditResult, auditLog, auditSchema, decodeCursor, encodeCursor, listAudit, logAudit };