"""Catalog/freshness view — render the warehouse SSOT inventory (per-symbol bar count + date range)."""
from __future__ import annotations

import datetime as dt


def _iso(ts: int) -> str:
    return dt.datetime.fromtimestamp(int(ts), dt.timezone.utc).strftime("%Y-%m-%d")


def format_catalog(rows: list[tuple[str, int, int, int]]) -> str:
    if not rows:
        return "warehouse is empty"
    header = f"{'symbol':<12}{'bars':>8}  {'first':<12}{'last':<12}"
    lines = [header, "-" * len(header)]
    for symbol, n, first_ts, last_ts in rows:
        lines.append(f"{symbol:<12}{n:>8}  {_iso(first_ts):<12}{_iso(last_ts):<12}")
    return "\n".join(lines)
