// Parameters for the inbox search endpoint (GET /unibox).
// Mirrors backend models.MailSearchParams. Empty / undefined fields are
// stripped before serialization so the URL stays clean.

/** Canonical mail folders, mirroring the backend Folder* constants. */
export type UniboxFolder =
  | "inbox"
  | "sent"
  | "drafts"
  | "archive"
  | "spam"
  | "trash";

export const UNIBOX_FOLDERS: UniboxFolder[] = [
  "inbox",
  "sent",
  "drafts",
  "archive",
  "spam",
  "trash",
];

export interface UniboxSearchParams {
  query?: string; // Free text — currently matched as subject ILIKE
  from?: string; // Sender substring
  /** Exact address match against sender or recipients (compose history). */
  address?: string;
  /** Message direction relative to our mailboxes. */
  direction?: "sent" | "received";
  /**
   * Selected account IDs. The server filters with email_id IN (…).
   * Use this directly when picking specific mailboxes, or set
   * `tagId` instead and let the filter UI resolve it into the set
   * of accounts that carry the tag.
   */
  accountIds?: string[];
  /**
   * UI-only convenience: when set, the filter sheet resolves the tag
   * to the matching account IDs at apply time. The server never sees
   * this field; it sees the resolved `accountIds` instead.
   */
  tagId?: string;
  unseen?: boolean; // Only unread
  /**
   * Snoozed scope. true = only snoozed threads; undefined = exclude
   * snoozed (default inbox view); "any" = no snooze filter at all
   * (debug only).
   */
  snoozed?: true | "any";
  /**
   * Folder scope. Undefined = every folder except spam and trash (the
   * combined view never shows junk).
   */
  folder?: UniboxFolder;
  /** Awaiting reply: threads where the last message was from us. */
  awaitingReply?: boolean;
  /** Agent drafts: threads with a pending inbox-agent reply draft. */
  agentDrafts?: boolean;
  /**
   * Conversation-label filter. Threads carrying any of these category
   * ids match. Sent to the server as `category_ids`.
   */
  categoryIds?: string[];
  since?: Date; // From date
  until?: Date; // To date
  sortBy?: "newest" | "oldest";
  cursor?: string;
  limit?: number;
}
