/**
 * Public types for the notification outbox.
 *
 * The outbox makes notification delivery durable: every dispatch event becomes
 * a row in NotificationOutbox, and a worker drains the table with bounded
 * retry. Network-bound channels (webhook, telegram) flow through here; the
 * synchronous channels (email via SMTP, in-app DB writes) stay on the hot
 * path because they have their own queues / are idempotent DB writes.
 *
 * This file imports no Prisma, no framework, no other outbox internals — keep
 * it that way. Callers depend on these types, never on `outbox.repository.ts`
 * or `outbox.dispatcher.ts` directly.
 */

// PR-27 (May 2026): pagerduty + teams added. webhook stays as the
// generic POST-with-JSON channel (slack/discord share its body
// shape); pagerduty hits Events API v2 with a specific schema; teams
// hits an Incoming Webhook with a MessageCard payload.
export type OutboxChannelType = 'webhook' | 'telegram' | 'pagerduty' | 'teams';

export interface OutboxInput {
    eventKey: string;
    eventType: string;
    channelType: OutboxChannelType;
    channelId: number | null;
    payload: string;
    maxAttempts?: number;
    nextAttemptAt?: Date;
}

export interface OutboxEntry {
    id: number;
    eventKey: string;
    eventType: string;
    channelType: OutboxChannelType;
    channelId: number | null;
    payload: string;
    attempts: number;
    maxAttempts: number;
    lastError: string | null;
    nextAttemptAt: Date;
    deliveredAt: Date | null;
    failedAt: Date | null;
    createdAt: Date;
}

export interface DeliverySuccess { ok: true; }
export interface DeliveryFailure { ok: false; error: string; }
export type DeliveryResult = DeliverySuccess | DeliveryFailure;

export interface TickResult {
    claimed: number;
    delivered: number;
    retried: number;
    permanentlyFailed: number;
}
