/**
 * Operational report filters. Mirrors `sales-filters.ts`: the parser is a
 * pure, unit-testable function so the route just hands it the query params.
 *
 * Beta scope is Area only (a berth-area scope). The shape is intentionally
 * an object so a Status dimension can be added later without a rename.
 */
export interface OperationalFilters {
  areas?: string[];
}

/**
 * Parse the `area` CSV query param into a free list of port-defined area
 * strings. Empty / whitespace entries are dropped. Drizzle parameterises
 * the downstream `inArray`, so unvalidated values are injection-safe.
 * Returns `undefined` when no areas are active (→ no filter).
 */
export function parseOperationalFilters(params: URLSearchParams): OperationalFilters | undefined {
  const raw = params.get('area');
  if (!raw) return undefined;
  const areas = raw
    .split(',')
    .map((s) => s.trim())
    .filter((s) => s.length > 0);
  if (areas.length === 0) return undefined;
  return { areas };
}
