import { Controller, Get } from "@nestjs/common";
import { CatalogCacheService, CatalogCacheSnapshot } from "./services/catalog-cache.service";

interface CatalogCacheHealthResponse {
  timestamp: string;
  metrics: CatalogCacheSnapshot;
  ttl: {
    catalogSeconds: number | null;
    eligibilitySeconds: number | null;
    staticSeconds: number | null;
    volatileSeconds: number;
  };
}

@Controller("health/catalog")
export class CatalogHealthController {
  constructor(private readonly catalogCache: CatalogCacheService) {}

  @Get("cache")
  getCacheMetrics(): CatalogCacheHealthResponse {
    const ttl = this.catalogCache.getTtlConfiguration();
    return {
      timestamp: new Date().toISOString(),
      metrics: this.catalogCache.getMetrics(),
      ttl,
    };
  }
}
