import { createSidecarProxy } from '../../sidecar/create-proxy';

// /api/email/* — auth, then forward to officer-email. No routes of its own and no mail knowledge: not a
// message, not a folder, not an IMAP or SMTP credential.
//
// The mail store, the 14 HTTP routes, account CRUD, resync and IMAP validation all used to live in this
// directory — ~1,800 lines against a 314-line sidecar, with the sidecar importing BACK into the platform
// to reach them. They are the sidecar's now.
//
// A from-scratch mailbox sync holds a proxied request open well past the 60s idle default, hence the
// timeout; it applies to the whole prefix because the proxy must not know which routes are slow.

const proxy = createSidecarProxy({
  name: 'email',
  prefix: '/api/email',
  timeoutSeconds: 1800,
});

export const emailRouter = proxy.router;

/** Base URL of the sidecar's HTTP server, or null if it hasn't reported in yet. */
export const getEmailServerUrl = proxy.getHttpUrl;
