import type { Channel } from './channels.js';
import type { ZyphonErrorDetails } from './errors.js';

export type MessageStatus =
  | 'submitted'
  | 'accepted'
  | 'delivered'
  | 'failed'
  | 'undelivered'
  | 'rejected';

export type ContentType = 'text' | 'html' | 'template';

export interface Attachment {
  filename: string;
  contentType: string;
  /** Base64-encoded file bytes (Email attachments, or Meta WhatsApp media upload). */
  content?: string;
  /** Public HTTPS media URL (WhatsApp media or Twilio MMS). */
  url?: string;
}

export interface ContentPayload {
  type: ContentType;
  subject?: string;
  body: string;
  template?: string;
  variables?: Record<string, string>;
  attachments?: Attachment[];
}

export interface SendRequest {
  channel: Channel;
  recipient: string;
  content: ContentPayload;
  metadata?: Record<string, unknown>;
}

export interface NormalizedMessage {
  message_id: string;
  request_id: string;
  application_id: string;
  channel: Channel;
  recipient: string;
  content: ContentPayload;
  metadata: Record<string, unknown>;
  created_at: number;
}

export interface AttemptRecord {
  provider: string;
  attempt_number: number;
  ok: boolean;
  error: string | null;
  latency_ms: number;
}

export interface SendResponse {
  message_id: string;
  request_id: string;
  status: MessageStatus;
  channel: Channel;
  provider: string | null;
  failover: boolean;
  attempts: AttemptRecord[];
  provider_response: Record<string, unknown> | null;
  latency_ms: number;
  error?: ZyphonErrorDetails;
}

