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

// /api/photos/* — auth, then forward to officer-photos. No routes of its own and no Immich knowledge:
// this file must never grow app logic.
//
// The sidecar owns the Immich contract and holds its API key.

const proxy = createSidecarProxy({
  name: 'photos',
  prefix: '/api/photos',
  // Originals and `download/archive` zips are large and Immich builds the archive as it streams it, so the
  // socket can sit quiet longer than the default 60s idle drop allows.
  timeoutSeconds: 600,
  // Immich judges an asset from its first few KB and rejects immediately, while we are still writing —
  // and the response is lost in the teardown, which is what made every large upload fail with an
  // unexplained empty 400. Buffering here removes the overlap. The sidecar does the same on its own hop
  // to Immich (sidecar/photos/routes.ts → readBodyCapped), and both are needed: fixing one alone still
  // lost the answer roughly two runs in three at 32 MB.
  bufferRequestBody: true,
});

export const photosRouter = proxy.router;

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