export type OutboxStatus = 'queued' | 'sending' | 'sent' | 'delivered' | 'failed';
export type ChannelPref = 'auto' | 'imessage' | 'sms';
export type ChannelUsed = 'imessage' | 'sms';

export interface OutboxRecord {
  readonly id: string;
  readonly deviceId: string;
  readonly recipient: string;
  readonly body: string;
  readonly priority: number;
  readonly channelPref: ChannelPref;
  readonly channelUsed: ChannelUsed | null;
  readonly notBefore: string;
  readonly status: OutboxStatus;
  readonly attempts: number;
  readonly maxAttempts: number;
  readonly error: string | null;
  readonly dedupeKey: string | null;
  readonly scheduleReason: string | null;
  /** When true, marking this reply sent also marks the recipient's thread read. */
  readonly markReadOnSend: boolean;
  readonly createdAt: string;
  readonly updatedAt: string;
  readonly sentAt: string | null;
}

export interface OutboxDraft {
  readonly deviceId: string;
  readonly recipient: string;
  readonly body: string;
  readonly priority: number;
  readonly channelPref: ChannelPref;
  readonly notBefore: string;
  readonly maxAttempts?: number;
  readonly dedupeKey?: string | null;
  readonly scheduleReason?: string | null;
  readonly markReadOnSend?: boolean;
}

/** A due item handed to the Mac client to send. */
export interface OutboxDueItem {
  readonly id: string;
  readonly recipient: string;
  readonly body: string;
  readonly channelPref: ChannelPref;
  readonly attempts: number;
  readonly maxAttempts: number;
}

export interface OutboxResultInput {
  readonly id: string;
  /** Authenticated device — scopes the mutation so a token can't touch others' rows. */
  readonly deviceId: string;
  readonly status: Extract<OutboxStatus, 'sent' | 'delivered' | 'failed'>;
  readonly channelUsed?: ChannelUsed | null;
  readonly error?: string | null;
}
